Program source Code
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 $line 1=< $fh >)) {
if ($line 1 =~/^windows/) {
Print "Windows IP configure:\n"
};
if ($line 1 =~/([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 $. " \ n ";
$mac _address = $;
};
if ($line 1 =~/(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 $. " \ n ";
$ip _address = $ $;
$mac _ip_hash{$mac _address}= $ip _address;
};
}
while (My ($key, $value) = each%mac_ip_hash) {
print "$key = $value \ n";
}
2. Program output:
C:\>perl ip_mac.pl
Windows IP Configure:
00-23-8b-75-ed-5f = 192.168.0.37
This article is from the "Yiyi" blog, make sure to keep this source http://heyiyi.blog.51cto.com/205455/1611046
Windows XP gets the NIC Mac and IP address