Where does ifconfig obtain the MAC address from in Linux?

  • Thread starter Thread starter j777
  • Start date Start date
  • Tags Tags
    Linux Mac
Click For Summary

Discussion Overview

The discussion revolves around how to obtain the MAC address of a Linux system, specifically questioning where the ifconfig command retrieves this information from. Participants explore various methods to access the MAC address directly, rather than through typical command outputs.

Discussion Character

  • Exploratory, Technical explanation

Main Points Raised

  • One participant inquires about directly reading the MAC address without using ifconfig or arp, seeking to understand the source of the MAC address in Linux.
  • Another participant suggests that ifconfig reads the MAC address from the kernel and mentions the possibility of finding it in the /proc filesystem.
  • A different approach is proposed involving the use of a socket object in Python to retrieve the MAC address, with an example provided for clarity.
  • One participant confirms the effectiveness of using a socket object to access the MAC address, referencing a specific example they found.

Areas of Agreement / Disagreement

Participants generally agree on the methods to access the MAC address, but there are multiple approaches discussed without a consensus on the best method.

Contextual Notes

Some methods rely on specific programming techniques or system interfaces, which may not be universally applicable across all Linux distributions or configurations.

Who May Find This Useful

Readers interested in Linux networking, system programming, or those looking to understand low-level network configurations may find this discussion relevant.

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:

Similar threads

  • · Replies 1 ·
Replies
1
Views
6K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
4
Views
2K
Replies
2
Views
2K
Replies
4
Views
3K
  • · Replies 13 ·
Replies
13
Views
4K
Replies
2
Views
2K
Replies
6
Views
3K