Where does ifconfig obtain the MAC address from in Linux?

  • Thread starter Thread starter j777
  • Start date Start date
  • Tags Tags
    Linux Mac
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 11K views
j777
Messages
148
Reaction score
0
Hello,

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?


Thanks
 
Physics news on Phys.org
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:
import socket
sock = socket.socket (socket.AF_PACKET,socket.SOCK_RAW)
sock.bind (("eth0", 9999))
mac = s.getsockname()[-1]
 
I actually just found this example which works.

Thanks for the help chroot and Sane.

http://english.geekpage.jp/programming/linux-network/get-macaddr.php"
 
Last edited by a moderator:
Haha, yes. That's exactly what I had suggested. :wink:

It looks at a socket object to see the MAC address.
 
Last edited: