2to3/manual: check_netconnections.py

This commit is contained in:
Sven Velt 2020-12-29 22:05:47 +01:00
parent 9be96f3705
commit c2336a1cd2

View file

@ -1,10 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
##################################################################### #####################################################################
# (c) 2010-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany # # (c) 2010-2011 by Sven Velt and team(ix) GmbH, Nuernberg, Germany #
# sv@teamix.net # # sv@teamix.net #
# (c) 2016 by Sven Velt, Germany # # (c) 2016- by Sven Velt, Germany #
# sven-mymonplugins@velt.biz # # sven-mymonplugins@velt.biz #
# # # #
# This file is part of "velt.biz - My Monitoring Plugins" # # This file is part of "velt.biz - My Monitoring Plugins" #
@ -30,19 +30,18 @@ import re
import sys import sys
try: try:
from monitoringplugin import MonitoringPlugin from MyMonPlugin import MonitoringPlugin
except ImportError: except ImportError:
print '==========================' print('==========================')
print 'AIKS! Python import error!' print('AIKS! Python import error!')
print '==========================\n' print('==========================\n')
print 'Could not find "monitoringplugin.py"!\n' print('Could not find class "MonitoringPlugin"!\n')
print 'Did you download "%s"' % os.path.basename(sys.argv[0]) print('Did you download "%s"' % os.path.basename(sys.argv[0]))
print 'without "monitoringplugin.py"?\n' print('without "MyMonPlugin/"?\n')
print 'Please go back to' print('Please go back to')
print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,' print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:')
print 'or even better:' print('- get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases')
print 'get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases' print('- or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n')
print 'or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n'
sys.exit(127) sys.exit(127)
@ -103,11 +102,8 @@ for version in versions:
matcher = v4match matcher = v4match
for proto in protos: for proto in protos:
filename = '/proc/net/%s%s' % (proto, version) with open('/proc/net/%s%s' % (proto, version)) as fh:
f = file(filename) for line in fh:
lines = f.readlines()
for line in lines:
m = matcher.match(line) m = matcher.match(line)
if m: if m:
port = int(m.group(2), 16) port = int(m.group(2), 16)