-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoui2hash.py
executable file
·39 lines (32 loc) · 1.13 KB
/
oui2hash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# to include this in your script, add the following line to your imports:
# from ouilookup import ouilookup_vals
import sys
import os
filename = sys.argv[1]
with open(filename, "r") as fh:
with open('oui_hashtable.txt', "w") as wfh:
for line in fh:
if("base 16" in line):
line = line.strip('\n')
linelist = line.split('\t')
oui = linelist[0].strip().replace(' (base 16)','')
vendor = linelist[2]
wfh.write(f'"{oui}":"{vendor}",\n')
wfh.write('"":None\n')
wfh.close()
fh.close()
os.system("sort -t':' -n -k1 oui_hashtable.txt > oui_hashtable_sorted.txt")
with open('oui_hashtable_sorted.txt', "r") as rfh:
with open('ouilookup.py', "w") as finalfh:
finalfh.write('#!/usr/bin/env python3\n')
finalfh.write('\n')
finalfh.write('# OUI hashtable\n')
finalfh.write('ouilookup_vals = {\n')
for line in rfh:
finalfh.write(line)
finalfh.write('}')
finalfh.close()
rfh.close()
os.remove('oui_hashtable.txt')
os.remove('oui_hashtable_sorted.txt')