Get MAC in Django / python

0

I want to get the mac from a device, I'm importing:

from uuid import getnode as get_mac


mac = get_mac()
print ('mac...>>>:',mac)

However, it brings digits that do not correspond to a MAC (00: 00: 00: 00: 00: 00)

    
asked by Noel L 14.06.2018 в 23:20
source

1 answer

1

To get your MAC address as you want, you just need to do something extra, leaving your code like this:

from uuid import getnode as get_mac

mac = get_mac()
mac = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
print ('MAC >>>: ', mac)

Basically what you do is convert that number that returns to hexadecimal and separate it from 2 in two by adding the corresponding :

    
answered by 14.06.2018 / 23:56
source