Browse Source

v1.2 now with Python 2.x and 3.x support.

Peter Siegrist 2 years ago
parent
commit
4603c9f098
2 changed files with 19 additions and 19 deletions
  1. 5 5
      README.md
  2. 14 14
      sinetstat

+ 5 - 5
README.md

@@ -1,6 +1,6 @@
 __sinetstat__
 
-An alternative to the standard __Linux netstat__  which shows you all the hidden IPv4 mapped network sockets.
+An alternative to the standard __Linux netstat__  which shows you all network sockets including hidden IPv4 in IPv6 mapped.
 
 
 
@@ -11,7 +11,7 @@ Improvements to the original netstat command:
 
   
   
-This is a Python 2.x script.  
+This is a Python 2.x/3.x script.  
 For a full featured output the script needs root-privileges.  
 
 
@@ -20,8 +20,8 @@ Simply try:
 <small><pre>
  # sinetstat -h
 usage: sinetstat [-h] [-l] [-e] [-r] [-w] [-W] [-t] [-u] [-4] [-6]
-netstat utility V1.0
-2017 by sigi <https://wiki.zweiernet.ch/wiki/sinetstat>
+netstat utility V1.2
+2017-2019 by sigi <https://wiki.zweiernet.ch/wiki/sinetstat>
 .
 optional arguments:
   -h, --help  show this help message and exit
@@ -66,7 +66,7 @@ TCP6    ::: 995                   ::: 0                     LISTEN       root
 (c) 2016 by Siegrist(SystemLoesungen) <sigi @ ZweierNet.ch>   
 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
 who had it adapted from Ricardo Pascal, available on http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code.

+ 14 - 14
sinetstat

@@ -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]
 # 
-# 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.
 #
 # 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_UDP4 = "/proc/net/udp"
@@ -149,7 +149,7 @@ def _compress_v6(addr):
     hextets = [int(x, 16) for x in addr.split(':')]
     #print hextets
     followingzeros = [0] * 8
-    for i in xrange(len(hextets)):
+    for i in range(len(hextets)):
         followingzeros[i] = _countFollowingZeros(hextets[i:])
     # compressionpos is the position where we can start removing zeros
     compressionpos = followingzeros.index(max(followingzeros))
@@ -493,7 +493,7 @@ if __name__ == '__main__':
     o_tcp = True
     o_v6 = 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 )
     parser.add_argument('-l', help="Only listening sockets", action="store_true")
     parser.add_argument('-e', help="Only established sockets", action="store_true")
@@ -528,26 +528,26 @@ if __name__ == '__main__':
     
     
     # 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"
     if o_v4 == True and o_tcp == True: 
         for conn_tcp in netstat_tcp4():
-            print conn_tcp
+            print(conn_tcp)
     #print "\nTCP (v4inv6) Results:\n"
     if o_v4 == True and o_tcp == True:
         for conn_tcp46 in netstat_tcp4in6():
-            print conn_tcp46
+            print(conn_tcp46)
     #print "\nTCP (v6) Results:\n"
     if o_v6 == True and o_tcp == True:
         for conn_tcp6 in netstat_tcp6():
-            print conn_tcp6
+            print(conn_tcp6)
     #print "\nUDP (v4) Results:\n"
     if o_v4 == True and o_udp == True and not args.l:
         for conn_udp in netstat_udp4():
-            print conn_udp
+            print(conn_udp)
     #print "\nUDP (v6) Results:\n"
     if o_v6 == True and o_udp == True and not args.l:
         for conn_udp6 in netstat_udp6():
-            print conn_udp6
+            print(conn_udp6)