Where does ifconfig obtain the MAC address from in Linux?

  • Thread starter j777
  • Start date
  • Tags
    Linux Mac
In summary, the conversation discusses ways to read the MAC address of a Linux system directly, without relying on the output of arp or ifconfig. One suggestion is to parse the output, while another is to look at a socket object. An example in Python is provided, and a helpful link is also shared.
  • #1
j777
148
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
  • #2
It reads it from the kernel. You can probably find it somewhere in the /proc filesystem.. I'll browse around.

- Warren
 
  • #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:
import socket
sock = socket.socket (socket.AF_PACKET,socket.SOCK_RAW)
sock.bind (("eth0", 9999))
mac = s.getsockname()[-1]
 
  • #4
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:
  • #5
Haha, yes. That's exactly what I had suggested. :wink:

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

1. How do I find the MAC address in Linux?

To find the MAC address in Linux, you can use the command "ifconfig" in the terminal. This will display the network interfaces on your system, along with their corresponding MAC addresses.

2. What is a MAC address in Linux?

A MAC address, also known as a physical address, is a unique identifier assigned to a network interface on a device. It is used for communication on a local network and is necessary for devices to identify and communicate with each other.

3. Can I change my MAC address in Linux?

Yes, you can change your MAC address in Linux using the "ifconfig" command with the "hw" option. This will allow you to specify a new MAC address for your network interface. However, keep in mind that changing your MAC address can potentially cause network connectivity issues.

4. How do I determine the manufacturer of a device using its MAC address in Linux?

You can use the "arp" command in Linux to determine the manufacturer of a device using its MAC address. This command will display the IP and MAC addresses of devices on your network, along with their corresponding manufacturer names.

5. Is it possible to spoof a MAC address in Linux?

Yes, it is possible to spoof a MAC address in Linux by using tools such as "macchanger" or manually changing it using the "ifconfig" command. However, this practice is not recommended as it can cause network issues and is often used for malicious purposes.

Similar threads

  • Programming and Computer Science
Replies
1
Views
505
Replies
3
Views
325
  • Programming and Computer Science
Replies
1
Views
3K
  • Computing and Technology
Replies
5
Views
1K
Replies
2
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
6
Views
3K
Replies
10
Views
2K
  • Computing and Technology
Replies
13
Views
2K
Back
Top