Skip to content

Instantly share code, notes, and snippets.

@sonalranjit
Forked from pklaus/README.md
Created August 23, 2016 20:50
Show Gist options
  • Save sonalranjit/639e0c3a4095d2f7cfab45ca9d972cf5 to your computer and use it in GitHub Desktop.
Save sonalranjit/639e0c3a4095d2f7cfab45ca9d972cf5 to your computer and use it in GitHub Desktop.
Generating Random MAC Addresses with Python

TODO

  • Create a CLI-Interface with the following options:
    • Unicast or Multicast? Default: Unicast
    • Locally Administered or Globally Unique? Default: Locally Administered
    • Prescribe specific OUI (overwrites the above two)
    • Number of MACs to generate (they should not collide and be piped out separated by newlines)

Resources

#!/usr/bin/env python
import random
def randomMAC():
return [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
def MACprettyprint(mac):
return ':'.join(map(lambda x: "%02x" % x, mac))
if __name__ == '__main__':
print(MACprettyprint(randomMAC()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment