Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Read MAC address in Linux

  1. Dec 15, 2006 #1

    Is there a way to read the MAC address of a linux system directly? ie not from the output of arp or ifconfig ---> Where does ifconfig read the MAC address from?

  2. jcsd
  3. Dec 15, 2006 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    It reads it from the kernel. You can probably find it somewhere in the /proc filesystem.. I'll browse around.

    - Warren
  4. Dec 15, 2006 #3
    Parsing the output, as you suggested, is one way. Looking at a socket object is another. I think this would probably be the best way to do it under Linux.

    Here's an example of how one might do this in Python:
    Code (Text):
    import socket
    sock = socket.socket (socket.AF_PACKET,socket.SOCK_RAW)
    sock.bind (("eth0", 9999))
    mac = s.getsockname()[-1]
  5. Dec 15, 2006 #4
  6. Dec 15, 2006 #5
    Haha, yes. That's exactly what I had suggested. :wink:

    It looks at a socket object to see the MAC address.
    Last edited: Dec 15, 2006
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Read MAC address in Linux
  1. Fortran in Linux (Replies: 3)

  2. Memory addresses (Replies: 7)

  3. Learn linux (Replies: 6)

  4. IP address (Replies: 2)