in reply to Re^2: How can I get current IP,DNS,MAC,GW under XP?
in thread How can I get current IP,DNS,MAC,GW under XP?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How can I get current IP,DNS,MAC,GW under XP?
by perllee (Novice) on Nov 23, 2008 at 09:37 UTC |