vvrao_2000 has asked for the wisdom of the Perl Monks concerning the following question:

May i know what r the method to mind MAC address of Linux Machines

janitored by ybiC: Correct mis-spelling in nodetitle s/Liumx/Linux/

Replies are listed 'Best First'.
Re: MAC address for Linux Machine
by belg4mit (Prior) on Apr 03, 2004 at 15:27 UTC
Re: MAC address for Linux Machine
by Abigail-II (Bishop) on Apr 03, 2004 at 09:48 UTC
    Machines don't have necessarely MAC addresses (although SUN/Solaris boxes will - sort of) - but network interfaces have. A machine can have 0 network interfaces, and hence, no MAC address. Or it could have a gazillion, and have a gazillion (or less) MAC addresses (more than one interface can have the same MAC address).

    Anyway, to get back to your question. The easy way is to call ifconfig and parse its output. The hard way is to call ioctl (with the appropriate arguments), and unpacking its return value.

    Abigail

      Right on, assuming that you're looking at the MAC address(es) of your local machine. If you want to find the address of a remote machine, it might be in your local ARP cache. Try parsing the output of /usr/sbin/arp on a Unix machine (keep in mind that the arguments to arp vary by operating system).

      Also, if the MAC address of interest isn't in your ARP cache, you can try pinging it with Net::Arping. It will allow you to ping a host using ARP packets and get the MAC address directly from the reply. This is a cool module, even if the documentation leaves a bit to be desired.

      Your system's ARP cache should cache the MAC addresses of machines on the local network with which it has recently communicated, so you may not even need to install the module depending on your environment.

      Here's another link on ARP and Linux if you're interested.

      % /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
        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

        A reply falls below the community's threshold of quality. You may see it by logging in.
      how can use in perl programm /sbin/ifconfig -a to find MAC of any IP in Linux hope you help me