Denis Banovic <[EMAIL PROTECTED]> writes:
> Hi!
>
> Is it possible to get the MAC Adress of a Remote PC in LAN or in the
> Internet?
First of all, there is no such thing as "the" MAC address. Any
machine can have multiple network adapters, both physical and virtual,
and you should decide right now what you really mean.
That said, you can use Win32::NetAdmin as Manfred Maier suggests, or
you can use WMI.
Below is a Perl script which takes a hostname as argument and dumps
some information about its bound and enabled TCP/IP adapters. With
"--all", it will dump info on all adapters, whether bound or not.
Follow the URL for Win32_NetworkAdapterConfiguration to learn what
else you can do with this class (which is quite a bit).
- Pat
use warnings;
use strict;
use Getopt::Long;
use Win32::OLE;
sub die_usage () {
die "Usage: $0 [ --all ] <hostname>\n";
}
my %opts;
GetOptions (\%opts, "all")
or die_usage ();
scalar @ARGV == 1
or die_usage ();
my ($hostname) = @ARGV;
# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);
# Get a handle to the SWbemServices object of the local machine.
my $computer = Win32::OLE->GetObject ("WinMgmts://$hostname/");
# Get the SWbemObjectSet of all network adapters. See:
#
<http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp>
my $adapters_set =
$computer->InstancesOf ('Win32_NetworkAdapterConfiguration');
# Convert set to a Perl array.
my @adapters = Win32::OLE::Enum->All ($adapters_set);
# Loop through them, printing various items of interest.
foreach my $adapter (@adapters) {
# Skip adapters for which TCP/IP is not bound and enabled, unless
# --all switch was given.
$opts{'all'} || ($adapter->{'IPEnabled'})
or next;
print "Index: $adapter->{'Index'}\n";
print "Caption: $adapter->{'Caption'}\n";
print "Service Name: $adapter->{'ServiceName'}\n";
my $mac_addr = $adapter->{'MACAddress'};
defined $mac_addr
and print "MAC Address: $mac_addr\n";
my $ipaddrs = $adapter->{'IPAddress'};
if (defined $ipaddrs) {
foreach my $ip (@$ipaddrs) {
print "IP Address: $ip\n";
}
}
print "\n";
}