Where does ifconfig obtain the MAC address from in Linux?

  • Thread starter Thread starter j777
  • Start date Start date
  • Tags Tags
    Linux Mac
AI Thread Summary
To read the MAC address of a Linux system directly, it is noted that the information is sourced from the kernel, specifically accessible through the /proc filesystem. A method discussed involves using socket programming in Python, where a raw socket is created and bound to a network interface, such as "eth0", to retrieve the MAC address. This approach is highlighted as effective for obtaining the MAC address without relying on commands like arp or ifconfig. The conversation also references an example code snippet that demonstrates this method successfully.
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
 
Technology news on Phys.org
It reads it from the kernel. You can probably find it somewhere in the /proc filesystem.. I'll browse around.

- Warren
 
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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top