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

% /sbin/ifconfig eth0 using this iam getting mac address,my application is that when i pass IP i want to get MAC address which is in Linux Server

Replies are listed 'Best First'.
Re: MAC address for Linux Machine
by Abigail-II (Bishop) on Apr 03, 2004 at 10:24 UTC
    It's quite unclear to me what you want. What do you mean by MAC address which is in Linux Server? If all you want is to get the MAC address of an IP address, given that the IP address belongs to the local subnet, you could issue an arp request. But that has nothing to do with a "Linux Server", whatever that may be.

    Abigail

      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

        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"
    A reply falls below the community's threshold of quality. You may see it by logging in.