mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 05:22:04 -07:00
new: updated mac vendor lookup with IEEE datasets
This commit is contained in:
parent
0dc5f66e27
commit
5858743b6e
9 changed files with 104569 additions and 84588 deletions
|
@ -1,58 +1,34 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env /usr/bin/python3
|
||||
import os
|
||||
import six
|
||||
import re
|
||||
import glob
|
||||
import csv
|
||||
import json
|
||||
|
||||
base = os.path.dirname(os.path.realpath(__file__))
|
||||
# "https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD"
|
||||
|
||||
# https://github.com/wireshark/wireshark/blob/master/tools/make-manuf.py
|
||||
|
||||
|
||||
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] != '#']
|
||||
data = {}
|
||||
|
||||
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
|
||||
for path in glob.glob("./manuf/*.csv"):
|
||||
with open(path, 'r') as fp:
|
||||
reader = csv.reader(fp.readlines())
|
||||
# Pop the title row.
|
||||
next(reader)
|
||||
for row in reader:
|
||||
(registry, assignment, org_name, org_addr) = row
|
||||
data[assignment] = org_name
|
||||
|
||||
# 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( '"', '\\"' ))
|
||||
for (key, vendor) in data.items():
|
||||
code += " \"%s\": %s,\n" % (key,
|
||||
json.dumps(vendor))
|
||||
|
||||
code += "}\n"
|
||||
|
||||
|
@ -60,3 +36,59 @@ code = template.replace('#MAP#', code)
|
|||
|
||||
with open(os.path.join(base, 'manuf.go'), 'w+t') as fp:
|
||||
fp.write(code)
|
||||
|
||||
"""
|
||||
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