Reputation: 185
Using the function I found from a forum/thread(listed below), I can find the MAC address of my computer in python. However, this function returns the wrong MAC address. This computer has an ethernet and Wireless lan adapter. The computer I am using uses the Wireless LAN adapter. How do I find what MAC the computer is using and what the the Physical Address(MAC) of that adapter is?
This is the code I found that returns the incorrect MAC:
def get_mac():
import uuid
return str(':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])).upper()
If any more information is necessary, please post a comment and I will add what I can
Thank you!
Upvotes: 1
Views: 6117
Reputation: 21
If you're using Linux you can find the list of adapters here: /sys/class/net/
And read the MAC address of a specific interface, for example eth0, like this:
with open('/sys/class/net/eth0/address') as f:
mac = f.read()
Upvotes: 2
Reputation: 2935
from uuid import getnode as get_mac
mac = get_mac()
Note: Please consdier may be it return octet or decimal and you watch hex in output of ifconfig
Upvotes: 1