mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: using wireshark manufacturers file instead of oui.dat (closes #303)
This commit is contained in:
parent
7ef447e726
commit
976465959e
13 changed files with 70433 additions and 45957 deletions
63
network/make_manuf.py
Executable file
63
network/make_manuf.py
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/python
|
||||
import os
|
||||
import six
|
||||
import re
|
||||
import sys
|
||||
|
||||
base = os.path.dirname(os.path.realpath(__file__))
|
||||
# "https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD"
|
||||
|
||||
with open(os.path.join(base, 'manuf.go.template')) as fp:
|
||||
template = fp.read()
|
||||
|
||||
with open(os.path.join(base, 'manuf')) as fp:
|
||||
lines = [l.strip() for l in fp.readlines()]
|
||||
lines = [l for l in lines if l != "" and l[0] != '#']
|
||||
|
||||
def get_mac_and_mask(mac):
|
||||
# simple case
|
||||
if not "/" in mac:
|
||||
mac_hex = mac.replace(":", '')
|
||||
mask = 48 - 4 * len(mac_hex)
|
||||
mac_int = int(mac_hex, 16) << mask
|
||||
|
||||
# 00:1B:C5:00:00:00/36
|
||||
else:
|
||||
parts = mac.split("/")
|
||||
mac_hex = parts[0].replace(":", '')
|
||||
mask = 48 - int(parts[1])
|
||||
mac_int = int(mac_hex, 16) << mask
|
||||
|
||||
return (mac_int, mask)
|
||||
|
||||
index = {}
|
||||
|
||||
for line in lines:
|
||||
m = re.match( r'^([^\s]+)\s+([^\s]+)(.*)$', line, re.M)
|
||||
parts = m.groups()
|
||||
mac = parts[0]
|
||||
short = parts[1]
|
||||
manuf = parts[2].strip()
|
||||
if manuf == "":
|
||||
manuf = short
|
||||
|
||||
m = re.match( r'^([^#]+)#.+$', manuf)
|
||||
if m is not None:
|
||||
manuf = m.groups()[0].strip()
|
||||
|
||||
mac_int, mask = get_mac_and_mask(mac)
|
||||
|
||||
key = "%d.%d" % ( mask, mac_int >> mask )
|
||||
index[key] = manuf
|
||||
|
||||
code = "map[string]string {\n"
|
||||
|
||||
for key, vendor in six.iteritems(index):
|
||||
code += " \"%s\": \"%s\",\n" % ( key, vendor.replace( '"', '\\"' ))
|
||||
|
||||
code += "}\n"
|
||||
|
||||
code = template.replace('#MAP#', code)
|
||||
|
||||
with open(os.path.join(base, 'manuf.go'), 'w+t') as fp:
|
||||
fp.write(code)
|
Loading…
Add table
Add a link
Reference in a new issue