diff --git a/src/opnsense/scripts/interfaces/list_arp.py b/src/opnsense/scripts/interfaces/list_arp.py index e490c5339..1b1b1917a 100755 --- a/src/opnsense/scripts/interfaces/list_arp.py +++ b/src/opnsense/scripts/interfaces/list_arp.py @@ -28,10 +28,8 @@ -------------------------------------------------------------------------------------- list arp table """ -import tempfile import subprocess import os -import os.path import sys import ujson import netaddr @@ -51,27 +49,24 @@ if __name__ == '__main__': dhcp_leases[dhcp_ipv4_address] = {'hostname': lease.split('client-hostname')[1].strip()[1:-2]} # parse arp output - with tempfile.NamedTemporaryFile() as output_stream: - subprocess.call(['/usr/sbin/arp', '-an'], stdout=output_stream, stderr=open(os.devnull, 'wb')) - output_stream.seek(0) - for line in output_stream: - line = line.decode() - line_parts = line.split() - if len(line_parts) > 3 and line_parts[3] != '(incomplete)': - record = {'mac': line_parts[3], - 'ip': line_parts[1][1:-1], - 'intf': line_parts[5], - 'manufacturer': '', - 'hostname': '' - } - manufacturer_mac = netaddr.EUI(record['mac']) - try: - record['manufacturer'] = manufacturer_mac.oui.registration().org - except netaddr.NotRegisteredError: - pass - if record['ip'] in dhcp_leases: - record['hostname'] = dhcp_leases[record['ip']]['hostname'] - result.append(record) + sp = subprocess.run(['/usr/sbin/arp', '-an'], capture_output=True, text=True) + for line in sp.stdout.split('\n'): + line_parts = line.split() + if len(line_parts) > 3 and line_parts[3] != '(incomplete)': + record = {'mac': line_parts[3], + 'ip': line_parts[1][1:-1], + 'intf': line_parts[5], + 'manufacturer': '', + 'hostname': '' + } + manufacturer_mac = netaddr.EUI(record['mac']) + try: + record['manufacturer'] = manufacturer_mac.oui.registration().org + except netaddr.NotRegisteredError: + pass + if record['ip'] in dhcp_leases: + record['hostname'] = dhcp_leases[record['ip']]['hostname'] + result.append(record) # handle command line argument (type selection) if len(sys.argv) > 1 and sys.argv[1] == 'json': diff --git a/src/opnsense/scripts/interfaces/list_ndp.py b/src/opnsense/scripts/interfaces/list_ndp.py index 3ade9fede..f815898ec 100755 --- a/src/opnsense/scripts/interfaces/list_ndp.py +++ b/src/opnsense/scripts/interfaces/list_ndp.py @@ -28,36 +28,30 @@ -------------------------------------------------------------------------------------- list ndp table """ -import tempfile import subprocess import os -import os.path import sys import ujson import netaddr if __name__ == '__main__': result = [] - # parse ndp output - with tempfile.NamedTemporaryFile() as output_stream: - subprocess.call(['/usr/sbin/ndp', '-an'], stdout=output_stream, stderr=open(os.devnull, 'wb')) - output_stream.seek(0) - data = output_stream.read().decode().strip() - for line in data.split('\n')[1:]: - line_parts = line.split() - if len(line_parts) > 3 and line_parts[1] != '(incomplete)': - record = {'mac': line_parts[1], - 'ip': line_parts[0], - 'intf': line_parts[2], - 'manufacturer': '' - } - manufacturer_mac = netaddr.EUI(record['mac']) - try: - record['manufacturer'] = manufacturer_mac.oui.registration().org - except netaddr.NotRegisteredError: - pass - result.append(record) + sp = subprocess.run(['/usr/sbin/ndp', '-an'], capture_output=True, text=True) + for line in sp.stdout.split('\n')[1:]: + line_parts = line.split() + if len(line_parts) > 3 and line_parts[1] != '(incomplete)': + record = {'mac': line_parts[1], + 'ip': line_parts[0], + 'intf': line_parts[2], + 'manufacturer': '' + } + manufacturer_mac = netaddr.EUI(record['mac']) + try: + record['manufacturer'] = manufacturer_mac.oui.registration().org + except netaddr.NotRegisteredError: + pass + result.append(record) # handle command line argument (type selection) if len(sys.argv) > 1 and sys.argv[1] == 'json':