From 404f796eb8a1f6b4f17d9af07f5add336fb0b670 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 13 May 2019 11:37:01 +0200 Subject: [PATCH] python2->3 scripts in src/opnsense/scripts/interfaces --- src/opnsense/scripts/interfaces/list_arp.py | 12 ++++++------ src/opnsense/scripts/interfaces/list_macdb.py | 7 ++++--- src/opnsense/scripts/interfaces/list_ndp.py | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/opnsense/scripts/interfaces/list_arp.py b/src/opnsense/scripts/interfaces/list_arp.py index 671fae571..0d4c22464 100755 --- a/src/opnsense/scripts/interfaces/list_arp.py +++ b/src/opnsense/scripts/interfaces/list_arp.py @@ -1,7 +1,7 @@ -#!/usr/local/bin/python2.7 +#!/usr/local/bin/python3.6 """ - Copyright (c) 2016 Ad Schellevis + Copyright (c) 2016-2019 Ad Schellevis All rights reserved. Redistribution and use in source and binary forms, with or without @@ -54,8 +54,8 @@ if __name__ == '__main__': with tempfile.NamedTemporaryFile() as output_stream: subprocess.call(['/usr/sbin/arp', '-an'], stdout=output_stream, stderr=open(os.devnull, 'wb')) output_stream.seek(0) - data = output_stream.read().strip() - for line in data.split('\n'): + 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], @@ -78,6 +78,6 @@ if __name__ == '__main__': print(ujson.dumps(result)) else: # output plain text (console) - print ('%-16s %-20s %-10s %-20s %s' % ('ip', 'mac', 'intf', 'hostname', 'manufacturer')) + print('%-16s %-20s %-10s %-20s %s' % ('ip', 'mac', 'intf', 'hostname', 'manufacturer')) for record in result: - print ('%(ip)-16s %(mac)-20s %(intf)-10s %(hostname)-20s %(manufacturer)s' % record) + print('%(ip)-16s %(mac)-20s %(intf)-10s %(hostname)-20s %(manufacturer)s' % record) diff --git a/src/opnsense/scripts/interfaces/list_macdb.py b/src/opnsense/scripts/interfaces/list_macdb.py index e92ed093e..8d2c2b7e9 100755 --- a/src/opnsense/scripts/interfaces/list_macdb.py +++ b/src/opnsense/scripts/interfaces/list_macdb.py @@ -1,7 +1,7 @@ -#!/usr/local/bin/python2.7 +#!/usr/local/bin/python3.6 """ - Copyright (c) 2016 Ad Schellevis + Copyright (c) 2016-2019 Ad Schellevis All rights reserved. Redistribution and use in source and binary forms, with or without @@ -37,7 +37,8 @@ import netaddr.eui.ieee if __name__ == '__main__': result=dict() if os.path.isfile(netaddr.eui.ieee.OUI_REGISTRY_PATH): - for line in open(netaddr.eui.ieee.OUI_REGISTRY_PATH).read().split('\n'): + for line in open(netaddr.eui.ieee.OUI_REGISTRY_PATH, 'rb'): + line = line.decode() if line.find('(base 16)') > -1: parts=line.split('(base 16)') if len(parts) >= 2: diff --git a/src/opnsense/scripts/interfaces/list_ndp.py b/src/opnsense/scripts/interfaces/list_ndp.py index 1aae85396..6a632d4fd 100755 --- a/src/opnsense/scripts/interfaces/list_ndp.py +++ b/src/opnsense/scripts/interfaces/list_ndp.py @@ -1,7 +1,7 @@ -#!/usr/local/bin/python2.7 +#!/usr/local/bin/python3.6 """ - Copyright (c) 2016 Ad Schellevis + Copyright (c) 2016-2019 Ad Schellevis All rights reserved. Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ if __name__ == '__main__': 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().strip() + 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)':