Skip to content

Instantly share code, notes, and snippets.

@tbaschak
Created October 26, 2018 22:03
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 tbaschak/fb4ff373c9eac9bc0a50d094b16adf4e to your computer and use it in GitHub Desktop.
Save tbaschak/fb4ff373c9eac9bc0a50d094b16adf4e to your computer and use it in GitHub Desktop.
generates a mac address in the mikrotik bridge range
#!/usr/bin/env python
# 00:00:5E:80:00:00 - 00:00:5E:FF:FF:FF
import random
from os.path import expanduser
def rand_mac():
return "%02x:%02x:%02x:%02x:%02x:%02x" % (
0, 0, 94,
random.randint(128, 255),
random.randint(0, 255),
random.randint(0, 255)
)
def store_mac(mac):
home = expanduser("~")
hrm = open(home + "/.random_mac","a")
hrm.write(mac + "\n")
hrm.close()
def check_mac(mac):
matched = False
home = expanduser("~")
file = open(home + "/.random_mac","r")
for line in file:
line = line.rstrip('\n')
if line == mac:
matched = True
return matched
macaddy = rand_mac()
while check_mac(macaddy) == True:
macaddy = rand_mac()
print macaddy
store_mac(macaddy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment