Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2017 10:44
What would you like to do?
Generates a random mac address with real OUI
import random
# wget
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()
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