Python: How to get the MAC Address

Here is an example code to help you get the mac address with python.


How to get the MAC Address with python

def Getphysicaladdress(self):

    import uuid
    node = uuid.getnode()
    macHex = uuid.UUID(int=node).hex[-12:]
    mac = []
    for i in range(len(macHex))[::2]:
        mac.append(macHex[i:i + 2])
    mac = ':'.join(mac)
    print('MAC:', mac)

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *