Generates a random mac address with real OUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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