windows XP 获取网卡MAC和IP地址

  1. 程序源码


use strict;

open my $fh,"ipconfig /all|" or die "can't find cmd ipconfig /all:$!";

my (%mac_ip_hash, $ip_address, $mac_address);

while(defined(my $line1=<$fh>)){

    if ($line1 =~ /^Windows/){

print "Windows IP Configure:\n" 

};

    if ($line1 =~ /([0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F]-[0-9A-F][0-9A-F])+?/)

{

#print $1."\n";

$mac_address = $1;

};

    if ($line1 =~ /(IP.*)(\s+)((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))/){

#print $3."\n";

$ip_address = $3;

$mac_ip_hash{$mac_address}=$ip_address;

};

}

  

while(my ($key, $value) = each %mac_ip_hash){  

print "$key => $value\n";  


2.程序输出:


C:\>perl ip_mac.pl

Windows IP Configure:

00-23-8B-75-ED-5F => 192.168.0.37

本文转自 pgmia 51CTO博客,原文链接:http://blog.51cto.com/heyiyi/1611046


上一篇:Windows Server入门系列之十四 IP地址配置


下一篇:MHA高可用Mysql