Created
October 26, 2018 22:03
-
-
Save tbaschak/fb4ff373c9eac9bc0a50d094b16adf4e to your computer and use it in GitHub Desktop.
generates a mac address in the mikrotik bridge range
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
#!/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