Skip to content

Instantly share code, notes, and snippets.

@djoreilly
Created November 30, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djoreilly/6991817b42805c1a556b43bec6a7eda3 to your computer and use it in GitHub Desktop.
Save djoreilly/6991817b42805c1a556b43bec6a7eda3 to your computer and use it in GitHub Desktop.
Generates a random mac address with real OUI
import random
# wget http://standards-oui.ieee.org/oui.txt
OUI_FILE = 'oui.txt'
SEP = ':'
with open(OUI_FILE) as f:
lines = f.readlines()
while True:
line = random.choice(lines)
if 'base 16' in line:
oui_b16 = line[0:6]
vendor = line[20:].strip()
break
lower_bits = "%x" % random.randint(0x100000, 0xffffff-1)
lower_bits = lower_bits.upper()
mac_b16 = oui_b16 + lower_bits
mac = SEP.join([mac_b16[i:i+2] for i in range(0, 12, 2)])
#print vendor
print mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment