-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmake_oui_table.py
executable file
·68 lines (55 loc) · 1.78 KB
/
make_oui_table.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
"""make oui table - download the oui table from the ieee and build a table of
oui prefix, owner
also, normalize spelling of common owners that have multiple spellings
"""
import os
import httplib2
import csv
import re
URL="http://standards.ieee.org/regauth/oui/oui.txt"
common_mappings = (
('^apple[, ]', 'Apple'),
('^Hon Hai Precision', 'Hon Hai Precision Ind.'),
('^Intel ', 'Intel'),
('^Gemtek Technology', 'Gemtek Technology'),
('^askey ', 'Askey computer corp'),
('^LITE-ON Technology Corp', 'Liteon Technology Corporation'),
('^Liteon Tech Corp', 'Liteon Technology Corporation'),
('^RIM', 'Research In Motion'),
('^RIM Testing Services', 'Research In Motion'),
('^AzureWave Technologies', 'AzureWave Technologies'),
('^High Tech Computer Corp', 'HTC Corporation'),
('^Cisco.*Systems', 'Cisco'),
('Cisco.Linksys', 'Cisco-Linksys'),
('^Dell ', 'Dell'),
)
def get_file():
http = httplib2.Http(os.path.expanduser("~/.httplib2_cache"))
resp, content = http.request(URL)
return content
def get_hex_records(data):
for line in data:
if '(hex)' in line:
yield line
def parse_records(hex):
for x in hex:
parts = x.split("\t")
mac = parts[0].split()[0].replace("-",":").lower()
owner = fix_owner(parts[2])
yield mac, owner
def fix_owner(owner):
for regex, new_name in common_mappings:
if re.search(regex, owner, re.IGNORECASE):
return new_name
return owner
def main():
data = get_file().splitlines()
hex = get_hex_records(data)
records = parse_records(hex)
f = csv.writer(open("oui_table.csv",'w'))
f.writerow(("oui","owner"))
for x in records:
f.writerow(x)
if __name__ == "__main__":
main()