Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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