1

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!

2 Answers 2

2

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Does not work for every system, some do not have sys virtual filesystem.
1
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

7 Comments

Right now I am using the exact same thing. The code I am using uses uuid.getnode() and adds colons every 2 characters
Did you check for octet or decimal , Also check for all of interfaces, use ifconfig -a
I am using Windows. ipconfig /all shows me my MAC address. But how do I use this in python
>>> import os >>> os.system("ipconfig /all")
How do I search through to find my MAC though? Would I have to use regex?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.