mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 00:24:40 +00:00
Interfaces / Diagnostics / arp,ndp table: slow manufacturer lookups, likely after upgrading netaddr to 0.8.0. for https://github.com/opnsense/core/issues/4666
This commit is contained in:
parent
88e463c913
commit
dd2231ee54
@ -37,6 +37,14 @@ sys.path.insert(0, "/usr/local/opnsense/site-python")
|
||||
import watchers.dhcpd
|
||||
|
||||
if __name__ == '__main__':
|
||||
# index mac database (shipped with netaddr)
|
||||
macdb = dict()
|
||||
with open("%s/eui/oui.txt" % os.path.dirname(netaddr.__file__)) as fh_macdb:
|
||||
for line in fh_macdb:
|
||||
if line[11:].startswith('(hex)'):
|
||||
macprefix = line[0:8].replace('-', ':').lower()
|
||||
macdb[macprefix] = line[18:].strip()
|
||||
|
||||
result = []
|
||||
|
||||
# import dhcp_leases (index by ip address)
|
||||
@ -64,11 +72,8 @@ if __name__ == '__main__':
|
||||
'manufacturer': '',
|
||||
'hostname': ''
|
||||
}
|
||||
manufacturer_mac = netaddr.EUI(record['mac'])
|
||||
try:
|
||||
record['manufacturer'] = manufacturer_mac.oui.registration().org
|
||||
except netaddr.NotRegisteredError:
|
||||
pass
|
||||
if record['mac'][0:8] in macdb:
|
||||
record['manufacturer'] = macdb[record['mac'][0:8]]
|
||||
if record['ip'] in dhcp_leases:
|
||||
record['hostname'] = dhcp_leases[record['ip']]['hostname']
|
||||
result.append(record)
|
||||
|
||||
@ -35,6 +35,14 @@ import ujson
|
||||
import netaddr
|
||||
|
||||
if __name__ == '__main__':
|
||||
# index mac database (shipped with netaddr)
|
||||
macdb = dict()
|
||||
with open("%s/eui/oui.txt" % os.path.dirname(netaddr.__file__)) as fh_macdb:
|
||||
for line in fh_macdb:
|
||||
if line[11:].startswith('(hex)'):
|
||||
macprefix = line[0:8].replace('-', ':').lower()
|
||||
macdb[macprefix] = line[18:].strip()
|
||||
|
||||
result = []
|
||||
# parse ndp output
|
||||
sp = subprocess.run(['/usr/sbin/ndp', '-an'], capture_output=True, text=True)
|
||||
@ -46,11 +54,8 @@ if __name__ == '__main__':
|
||||
'intf': line_parts[2],
|
||||
'manufacturer': ''
|
||||
}
|
||||
manufacturer_mac = netaddr.EUI(record['mac'])
|
||||
try:
|
||||
record['manufacturer'] = manufacturer_mac.oui.registration().org
|
||||
except netaddr.NotRegisteredError:
|
||||
pass
|
||||
if record['mac'][0:8] in macdb:
|
||||
record['manufacturer'] = macdb[record['mac'][0:8]]
|
||||
result.append(record)
|
||||
|
||||
# handle command line argument (type selection)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user