python2->3 scripts in src/opnsense/scripts/interfaces

This commit is contained in:
Ad Schellevis 2019-05-13 11:37:01 +02:00
parent 61ebecddfb
commit 404f796eb8
3 changed files with 13 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#!/usr/local/bin/python2.7
#!/usr/local/bin/python3.6
"""
Copyright (c) 2016 Ad Schellevis <ad@opnsense.org>
Copyright (c) 2016-2019 Ad Schellevis <ad@opnsense.org>
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)

View File

@ -1,7 +1,7 @@
#!/usr/local/bin/python2.7
#!/usr/local/bin/python3.6
"""
Copyright (c) 2016 Ad Schellevis <ad@opnsense.org>
Copyright (c) 2016-2019 Ad Schellevis <ad@opnsense.org>
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:

View File

@ -1,7 +1,7 @@
#!/usr/local/bin/python2.7
#!/usr/local/bin/python3.6
"""
Copyright (c) 2016 Ad Schellevis <ad@opnsense.org>
Copyright (c) 2016-2019 Ad Schellevis <ad@opnsense.org>
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)':