|
@@ -1,11 +1,11 @@
|
|
-#!/usr/bin/python2
|
|
|
|
|
|
+#!/usr/bin/python
|
|
|
|
|
|
-# (c) 2016 by Siegrist(SystemLoesungen) <PSS @ ZweierNet.ch>
|
|
|
|
|
|
+# (c) 2016-2019 by Siegrist(SystemLoesungen) <PSS @ ZweierNet.ch>
|
|
# Website: [https://wiki.zweiernet.ch/wiki/Sinetstat]
|
|
# Website: [https://wiki.zweiernet.ch/wiki/Sinetstat]
|
|
#
|
|
#
|
|
-# This program is free software.
|
|
|
|
|
|
+# This program is free software under the terms of the GNU General Public License.
|
|
#
|
|
#
|
|
-# The program is based on a python netstat script that was written by da667 available on https://github.com/da667/netstat
|
|
|
|
|
|
+# Based on a python netstat script that was written by da667 available on https://github.com/da667/netstat
|
|
# who had it adapted from Ricardo Pascal, available on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code.
|
|
# who had it adapted from Ricardo Pascal, available on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code.
|
|
#
|
|
#
|
|
# This version has some improvements make it an acceptable alternative to the original netstat command.
|
|
# This version has some improvements make it an acceptable alternative to the original netstat command.
|
|
@@ -28,7 +28,7 @@ import argparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-VERSION = '1.1'
|
|
|
|
|
|
+VERSION = '1.2'
|
|
|
|
|
|
PROC_TCP4 = "/proc/net/tcp"
|
|
PROC_TCP4 = "/proc/net/tcp"
|
|
PROC_UDP4 = "/proc/net/udp"
|
|
PROC_UDP4 = "/proc/net/udp"
|
|
@@ -149,7 +149,7 @@ def _compress_v6(addr):
|
|
hextets = [int(x, 16) for x in addr.split(':')]
|
|
hextets = [int(x, 16) for x in addr.split(':')]
|
|
#print hextets
|
|
#print hextets
|
|
followingzeros = [0] * 8
|
|
followingzeros = [0] * 8
|
|
- for i in xrange(len(hextets)):
|
|
|
|
|
|
+ for i in range(len(hextets)):
|
|
followingzeros[i] = _countFollowingZeros(hextets[i:])
|
|
followingzeros[i] = _countFollowingZeros(hextets[i:])
|
|
# compressionpos is the position where we can start removing zeros
|
|
# compressionpos is the position where we can start removing zeros
|
|
compressionpos = followingzeros.index(max(followingzeros))
|
|
compressionpos = followingzeros.index(max(followingzeros))
|
|
@@ -493,7 +493,7 @@ if __name__ == '__main__':
|
|
o_tcp = True
|
|
o_tcp = True
|
|
o_v6 = True
|
|
o_v6 = True
|
|
o_v4 = True
|
|
o_v4 = True
|
|
- parser = argparse.ArgumentParser(description='netstat utility V'+VERSION+"\n2017 by sigi <https://wiki.zweiernet.ch/wiki/sinetstat>",
|
|
|
|
|
|
+ parser = argparse.ArgumentParser(description='netstat utility V'+VERSION+"\n2017-2019 by sigi <https://wiki.zweiernet.ch/wiki/sinetstat>",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter )
|
|
formatter_class=argparse.RawDescriptionHelpFormatter )
|
|
parser.add_argument('-l', help="Only listening sockets", action="store_true")
|
|
parser.add_argument('-l', help="Only listening sockets", action="store_true")
|
|
parser.add_argument('-e', help="Only established sockets", action="store_true")
|
|
parser.add_argument('-e', help="Only established sockets", action="store_true")
|
|
@@ -528,26 +528,26 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
# Output
|
|
# Output
|
|
- print '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('Proto', 'Local Address', 'Remote Address', 'State', 'UID', 'PID', 'Program')
|
|
|
|
- print '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('-----', '-------------', '--------------', '-----', '---', '---', '-------')
|
|
|
|
|
|
+ print('%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('Proto', 'Local Address', 'Remote Address', 'State', 'UID', 'PID', 'Program'))
|
|
|
|
+ print('%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('-----', '-------------', '--------------', '-----', '---', '---', '-------'))
|
|
#print "\nTCP (v4) Results:\n"
|
|
#print "\nTCP (v4) Results:\n"
|
|
if o_v4 == True and o_tcp == True:
|
|
if o_v4 == True and o_tcp == True:
|
|
for conn_tcp in netstat_tcp4():
|
|
for conn_tcp in netstat_tcp4():
|
|
- print conn_tcp
|
|
|
|
|
|
+ print(conn_tcp)
|
|
#print "\nTCP (v4inv6) Results:\n"
|
|
#print "\nTCP (v4inv6) Results:\n"
|
|
if o_v4 == True and o_tcp == True:
|
|
if o_v4 == True and o_tcp == True:
|
|
for conn_tcp46 in netstat_tcp4in6():
|
|
for conn_tcp46 in netstat_tcp4in6():
|
|
- print conn_tcp46
|
|
|
|
|
|
+ print(conn_tcp46)
|
|
#print "\nTCP (v6) Results:\n"
|
|
#print "\nTCP (v6) Results:\n"
|
|
if o_v6 == True and o_tcp == True:
|
|
if o_v6 == True and o_tcp == True:
|
|
for conn_tcp6 in netstat_tcp6():
|
|
for conn_tcp6 in netstat_tcp6():
|
|
- print conn_tcp6
|
|
|
|
|
|
+ print(conn_tcp6)
|
|
#print "\nUDP (v4) Results:\n"
|
|
#print "\nUDP (v4) Results:\n"
|
|
if o_v4 == True and o_udp == True and not args.l:
|
|
if o_v4 == True and o_udp == True and not args.l:
|
|
for conn_udp in netstat_udp4():
|
|
for conn_udp in netstat_udp4():
|
|
- print conn_udp
|
|
|
|
|
|
+ print(conn_udp)
|
|
#print "\nUDP (v6) Results:\n"
|
|
#print "\nUDP (v6) Results:\n"
|
|
if o_v6 == True and o_udp == True and not args.l:
|
|
if o_v6 == True and o_udp == True and not args.l:
|
|
for conn_udp6 in netstat_udp6():
|
|
for conn_udp6 in netstat_udp6():
|
|
- print conn_udp6
|
|
|
|
|
|
+ print(conn_udp6)
|
|
|
|
|