-
Notifications
You must be signed in to change notification settings - Fork 0
/
oui.py
executable file
·59 lines (38 loc) · 1.24 KB
/
oui.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
#!/usr/bin/env python3
# coding: utf-8
#
# Version 2019.01.08
#
import os
import re
import sys
def usage():
return '''
Usage: oui <mac address>
The MAC address can be in most any format of between 6 and 12 digits.
Eg. aabb.ccdd.eeff, aa:bb:cc:dd:ee:ff, aa:bb:cc, aabb.c, etc.
'''
def clean(unclean):
# Replace non-word chars.
return re.sub(r'\W+', '', unclean)
def get_oui_prefix(input):
return f"{input[:2]}:{input[2:4]}:{input[4:6]}".upper()
def get_mac_vendor(prefix):
wireshark_oui_file_path = ("/Applications/Wireshark.app/Contents"
"/Resources/share/wireshark/manuf")
if not os.path.exists(wireshark_oui_file_path):
print("I cannot find a Wireshark \"manuf\" file!")
with open(wireshark_oui_file_path, 'r') as f:
for line in f.readlines():
# This is crap and should be case-insensitive.
if line.startswith(prefix):
return line.rstrip()
return f"Result not found for: {prefix}"
def main():
if len(sys.argv) != 2:
print(usage())
sys.exit(1)
unclean_addr = sys.argv[1]
print("{}".format(get_mac_vendor(get_oui_prefix(clean(unclean_addr)))))
if __name__ == "__main__":
main()