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 | |
by bingos (Vicar) on Nov 21, 2008 at 12:14 UTC | |
by perllee (Novice) on Nov 23, 2008 at 09:37 UTC |