Last active
October 6, 2020 20:51
-
-
Save jeroenbrons/b56f4c53d099acd6eab8b9a7ed2bc6d8 to your computer and use it in GitHub Desktop.
Script to turn DECnet Area-number and Nodenumber into a MAC-adress for SIMH
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/python | |
#BY SPARCie | |
import sys, getopt, numpy | |
firstoctets = 'AA-00-04-00' | |
def main(argv): | |
area = '' | |
firstFour = 'AA-00-04-00' | |
node = '' | |
try: | |
opts, args = getopt.getopt(argv,"ha:n:",["area=","node="]) | |
except getopt.GetoptError: | |
print('convertmactodnet.py -a <areanr> -n <nodenr>') | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print('convertmactodnet.py -a <areanr> -n <nodenr>') | |
sys.exit()convertmactodnet.py | |
elif opt in ("-a", "--area"): | |
area = arg | |
elif opt in ("-n", "--node"): | |
node = arg | |
area =int(area) | |
node = int(node) | |
prepcompute = int(area*1024+node) | |
compute = str(prepcompute) | |
hexprepcomp=hex(prepcompute) | |
strMac=str(hexprepcomp) | |
strMac=strMac[2:] | |
if len(strMac)==3: | |
strMac="0"+strMac | |
byteOne=strMac[2:].upper() | |
byteTwo=strMac[:2].upper() | |
decMAC=firstFour+"-"+byteOne+"-"+byteTwo | |
print(decMAC) | |
def swap32(x): | |
return int.from_bytes(x.to_bytes(4, byteorder='little'), byteorder='big', signed=False) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small typo or copy/paste misser: Line 19