in reply to How can I get current IP,DNS,MAC,GW under XP?

You can use WMI to query this type of information.

Consult the documentation for Win32_NetworkAdapterConfiguration

Here's something I very quickly threw together:

use strict; use warnings; use Win32::OLE qw(in); $|++; my $object = Win32::OLE->GetObject('winmgmts:{impersonationLevel=imper +sonate}!//' . '.' ); foreach my $nic ( in $object->InstancesOf('Win32_NetworkAdapterConfigu +ration') ) { next unless $nic->{IPEnabled}; print "Adapter: "; print $nic->{Caption}, "\n"; print "Default gateway: ", join(' ', @{ $nic->{DefaultIPGateway} }) +, "\n" if $nic->{DefaultIPGateway}; my %addresses; @addresses{ @{ $nic->{IPAddress} } } = @{ $nic->{IPSubnet} }; print "IP Addresses: \n"; print "IP: $_ Mask: ", $addresses{$_}, "\n" for keys %addresses; print "DNS Servers: ", join(' ', @{ $nic->{DNSServerSearchOrder} } +), "\n" if $nic->{DNSServerSearchOrder}; } exit 0;

Replies are listed 'Best First'.
Re^2: How can I get current IP,DNS,MAC,GW under XP?
by perllee (Novice) on Nov 20, 2008 at 15:58 UTC
    First of all,thank you, above all enthusiastic response. But I think I do not have a clear description of the question. I do not need have a list of IP,DNS,etc on all NICs. In fact, I would like to know which NIC is working,then get the IP,DNS,MAC,etc on that NIC.

    For example, c:>ipconfig/all

    Windows IP Configuration Host Name . . . . . . . . . . . . : perl Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Unknown IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No Ethernet adapter VMware Network Adapter VMnet8: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : VMware Virtual Ethernet Ad +apter for VMnet8 Physical Address. . . . . . . . . : 00-50-56-C0-11-08 Dhcp Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : 192.168.227.1 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : Ethernet adapter VMware Network Adapter VMnet1: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : VMware Virtual Ethernet Ad +apter for VMnet1 Physical Address. . . . . . . . . : 00-50-56-C0-11-01 Dhcp Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : 192.168.138.1 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : Ethernet adapter 无线网络连接: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Broadcom 802.11b/g WLAN Physical Address. . . . . . . . . : 00-1A-73-2A-E6-BC Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.0.103 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.0.1 DHCP Server . . . . . . . . . . . : 192.168.0.1 DNS Servers . . . . . . . . . . . : 192.168.0.1 Lease Obtained. . . . . . . . . . : 2008年11月20日 23:35:02 Lease Expires . . . . . . . . . . : 2008年11月27日 23:35:02 Ethernet adapter 本地连接: Media State . . . . . . . . . . . : Media disconnected Description . . . . . . . . . . . : Broadcom NetLink (TM) Giga +bit Ethernet Physical Address. . . . . . . . . : 00-17-A4-DD-F3-26
    Now, I'm using a wireless network, so I hope the perl script will Automatically get the following:
    Physical Address. . . . . . . . . : 00-1A-73-2A-E6-BC IP Address. . . . . . . . . . . . : 192.168.0.103 Default Gateway . . . . . . . . . : 192.168.0.1 DHCP Server . . . . . . . . . . . : 192.168.0.1 DNS Servers . . . . . . . . . . . : 192.168.0.1
    Poor English skills, understanding.

    Thanks.

      Oh well, I'm feeling generous:

      use strict; use warnings; use Win32::OLE qw(in); $|++; my $machine = '.'; # Replace this to query a remote machine '.' picks +the localhost my $object = Win32::OLE->GetObject('winmgmts:{impersonationLevel=imper +sonate}!//' . $machine ); foreach my $nic ( in $object->InstancesOf('Win32_NetworkAdapterConfigu +ration') ) { next unless $nic->{IPEnabled}; next if $nic->{Caption} =~ /VMware Virtual/; # Mac Address print $nic->{MACAddress}, "\n"; # IP Address(es), there can be more than one print join( ' ', @{ $nic->{IPAddress} } ), "\n"; # Default gateway print join(' ', @{ $nic->{DefaultIPGateway} }), "\n" if $nic->{Defa +ultIPGateway}; # DHCP Server ( if applicable ) print $nic->{DHCPServer}, "\n" if $nic->{DHCPEnabled}; # DNS Servers ( if applicable ) print join(' ', @{ $nic->{DNSServerSearchOrder} } ), "\n" if $nic-> +{DNSServerSearchOrder}; } exit 0;

      Produces something like:

      00:11:2F:41:E5:CE 10.0.127.254 10.4.0.3 10.1.0.7 10.1.0.8 10.1.0.7
        Thank you for your advice.