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


本文出自 “yiyi” 博客,请务必保留此出处http://heyiyi.blog.51cto.com/205455/1611046

windows XP 获取网卡MAC和IP地址

上一篇:WinForm程序安装、发布流程


下一篇:WPF中使用MVVM创建一个简单的框架