in reply to Re: MAC address for Linux Machine
in thread MAC address for Linux Machine

sub unique { keys %{{ map { $_, 1 } @_ }} } my $ifconfig; -x and $ifconfig = $_ , last for qw(/sbin/ifconfig /bin/ifconfig); die "Can't find ifconfig\n" unless $ifconfig; my @hwaddrs = `$ifconfig` =~ /\b((?:[a-f\d]{2}:){5}[a-f\d]{2})\b/gi; { local ($\, $,) = ("\n", "\n") and print unique @hwaddrs }

iam this code to get MAC address ,but my application is if i give IP i want to get MAC address of remote IP

20040403 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: Re: Re: MAC address for Linux Machine
by nimdokk (Vicar) on Apr 03, 2004 at 22:11 UTC
    This may have already been mentioned, but I'll mention it again:

    C:\> arp -a <ip-address> (Windows)

    or

    $ /sbin/arp <ip-address> (Linux)

    will give you the MAC address of the specified IP address. You will need to parse the output if you are using this in a script, but the third field (HWaddress) is the one you want to look at.

    update: arp will only return valid information about an IP address for other addresses on the same subnet. So, if the IP address you are asking about is beyond a router (or switch), then you will only be able to get information about the nearside router interface. Thanks to yibC for pointing this out.


    "Ex Libris un Peut de Tout"