Skip to content

Instantly share code, notes, and snippets.

@akash0x53
Created February 13, 2015 11:34
Show Gist options
  • Save akash0x53/2bc7e6efe089a79eb8a0 to your computer and use it in GitHub Desktop.
Save akash0x53/2bc7e6efe089a79eb8a0 to your computer and use it in GitHub Desktop.
convert uuid.getnode to MAC address format
>>> import uuid
>>> mac="%12X" % uuid.getnode()
>>> mac
'48D224921B7C'
>>> mac[::2]
'4D2917'
>>> mac[1::2]
'8242BC'
>>> map(None, *(mac[::2], mac[1::2]))
[('4', '8'), ('D', '2'), ('2', '4'), ('9', '2'), ('1', 'B'), ('7', 'C')]
>>> ':'.join([''.join(i) for i in map(None, *(mac[::2], mac[1::2]))])
'48:D2:24:92:1B:7C'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment