diff --git a/Makefile b/Makefile index 628e8cd6f..9e6ed8aa9 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ CORE_DEPENDS?= apinger \ py27-requests \ py27-sqlite3 \ py27-ujson \ + py27-netaddr \ python27 \ radvd \ rate \ diff --git a/src/opnsense/scripts/interfaces/list_arp.py b/src/opnsense/scripts/interfaces/list_arp.py index 640b720ed..ed33d45fb 100755 --- a/src/opnsense/scripts/interfaces/list_arp.py +++ b/src/opnsense/scripts/interfaces/list_arp.py @@ -34,17 +34,11 @@ import os import os.path import sys import ujson +from netaddr import * if __name__ == '__main__': result = [] - # import mac manufacturer mac address table (index by mac prefix) - mac_table = {} - if os.path.isfile('/usr/local/share/nmap/nmap-mac-prefixes'): - for mac in open('/usr/local/share/nmap/nmap-mac-prefixes').read().split('\n'): - if len(mac) > 8: - mac_table[mac[0:6]] = mac[7:] - # import dhcp_leases (index by ip address) dhcp_leases = {} dhcp_leases_filename = '/var/dhcpd/var/db/dhcpd.leases' @@ -70,9 +64,10 @@ if __name__ == '__main__': 'manufacturer': '', 'hostname': '' } - manufacturer_mac = record['mac'].replace(':' ,'')[:6].upper() - if manufacturer_mac in mac_table: - record['manufacturer'] = mac_table[manufacturer_mac] + manufacturer_mac = EUI(record['mac']) + oui = manufacturer_mac.oui + if oui.registration().org: + record['manufacturer'] = oui.registration().org if record['ip'] in dhcp_leases: record['hostname'] = dhcp_leases[record['ip']]['hostname'] result.append(record) diff --git a/src/opnsense/scripts/interfaces/list_ndp.py b/src/opnsense/scripts/interfaces/list_ndp.py index a7174d51c..60f8491d8 100755 --- a/src/opnsense/scripts/interfaces/list_ndp.py +++ b/src/opnsense/scripts/interfaces/list_ndp.py @@ -34,17 +34,11 @@ import os import os.path import sys import ujson +from netaddr import * if __name__ == '__main__': result = [] - # import mac manufacturer mac address table (index by mac prefix) - mac_table = {} - if os.path.isfile('/usr/local/share/nmap/nmap-mac-prefixes'): - for mac in open('/usr/local/share/nmap/nmap-mac-prefixes').read().split('\n'): - if len(mac) > 8: - mac_table[mac[0:6]] = mac[7:] - # parse ndp output with tempfile.NamedTemporaryFile() as output_stream: subprocess.call(['/usr/sbin/ndp', '-an'], stdout=output_stream, stderr=open(os.devnull, 'wb')) @@ -58,9 +52,10 @@ if __name__ == '__main__': 'intf': line_parts[2], 'manufacturer': '' } - manufacturer_mac = record['mac'].replace(':' ,'')[:6].upper() - if manufacturer_mac in mac_table: - record['manufacturer'] = mac_table[manufacturer_mac] + manufacturer_mac = EUI(record['mac']) + oui = manufacturer_mac.oui + if oui.registration().org: + record['manufacturer'] = oui.registration().org result.append(record) # handle command line argument (type selection)