> I don't believe you can get the remote MAC address.

<snip>



The original post asked for the mac address of a remote host from a ping
response. I replied saying if it was on the same subnet, polling the
local arp cache would suffice. If the machine is not the on the same
subnet, I suggested nbtstat -A or WMI - ie not gleaning the information
from the ping but following up with another piece of code. Sort of akin
to calling the airport and asking about the flights :)


Method 1 - using arp - within your own subnet
=============================================

D:\shite>arp -a

Interface: 172.16.33.20 --- 0x2
  Internet Address      Physical Address      Type
  172.16.33.13          00-12-3f-73-f1-7a     dynamic
  172.16.33.21          00-12-3f-75-54-8a     dynamic
  172.16.33.62          00-0e-d7-96-aa-ff     dynamic

D:\shite>ping 172.16.33.21

Pinging 172.16.33.21 with 32 bytes of data:

Reply from 172.16.33.21: bytes=32 time<1ms TTL=128


Method 2 - WMI
==============

use Win32::OLE;

my $computer = "insert.remote.computer.here";

my $WMI      = Win32::OLE->GetObject("WinMgmts://$computer/root/cimv2")
or warn "Cannot instantiate WMI on $computer";
my $Adapters = $WMI->ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE
AdapterType = \"Ethernet 802.3\"");

foreach my $adapter (in $Adapters) {
        my $NetworkAdapterConfiguration =
$adapter->Associators_(undef,"Win32_NetworkAdapterConfiguration");
        my $Name = $adapter->{Name};
        my $MACAddress = $adapter->{MACAddress};
        print "$Name\t$MACAddress\n";
}

Method 3 - nbtstat
==================

D:\shite>nbtstat -A 172.16.1.100

Local Area Connection:
Node IpAddress: [172.16.33.20] Scope Id: []

           NetBIOS Remote Machine Name Table

       Name               Type         Status
    ---------------------------------------------
        <snip>
    MAC Address = 00-11-43-33-25-62

Methods 2 and 3 are just fine cross-subnet (method 2 requires admin
rights on the target machine). Sorry if my original reply wasn't clear.

Cheers,
Paul

*****************************************************************
Gloucester Research Limited believes the information 
provided herein is reliable. While every care has been 
taken to ensure accuracy, the information is furnished 
to the recipients with no warranty as to the completeness 
and accuracy of its contents and on condition that any 
errors or omissions shall not be made the basis for any 
claim, demand or cause for action.
*****************************************************************


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to