|
@@ -1,6 +1,6 @@
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
-# (c) 2016-2019 by Siegrist(SystemLoesungen) <PSS @ ZweierNet.ch>
|
|
|
+# (c) 2016-2022 by Siegrist(SystemLoesungen) <PSS @ ZweierNet.ch>
|
|
|
# Website: [https://wiki.zweiernet.ch/wiki/Sinetstat]
|
|
|
#
|
|
|
# This program is free software under the terms of the GNU General Public License.
|
|
@@ -28,7 +28,7 @@ import argparse
|
|
|
|
|
|
|
|
|
|
|
|
-VERSION = '1.3.1'
|
|
|
+VERSION = '1.4'
|
|
|
|
|
|
PROC_TCP4 = "/proc/net/tcp"
|
|
|
PROC_UDP4 = "/proc/net/udp"
|
|
@@ -226,11 +226,16 @@ def netstat_tcp4():
|
|
|
|
|
|
nline = '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('TCP4', l_host+': '+l_port, r_host+': '+r_port, state, uid, pid, exe)
|
|
|
|
|
|
- tcpresult.append(nline)
|
|
|
-
|
|
|
- # update v4inv6check list
|
|
|
- v4ports.append(l_port)
|
|
|
-
|
|
|
+ if o_reused == False:
|
|
|
+ if nline not in tcpresult: # Hide multi binds on same Socket (SO_REUSEPORT)
|
|
|
+ tcpresult.append(nline)
|
|
|
+ # update v4inv6check list
|
|
|
+ v4ports.append(l_port)
|
|
|
+ else:
|
|
|
+ tcpresult.append(nline)
|
|
|
+ # update v4inv6check list
|
|
|
+ v4ports.append(l_port)
|
|
|
+
|
|
|
return tcpresult
|
|
|
|
|
|
def netstat_tcp6():
|
|
@@ -274,8 +279,12 @@ def netstat_tcp6():
|
|
|
|
|
|
nline = '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('TCP6', _compress_v6(_convert_ipv6(line_array[1]))+': '+l_port, _compress_v6(_convert_ipv6(line_array[2]))+': '+r_port, state, uid, pid, exe)
|
|
|
|
|
|
- tcpresult.append(nline)
|
|
|
-
|
|
|
+ if o_reused == False:
|
|
|
+ if nline not in tcpresult: # Hide multi binds on same Socket (SO_REUSEPORT)
|
|
|
+ tcpresult.append(nline)
|
|
|
+ else:
|
|
|
+ tcpresult.append(nline)
|
|
|
+
|
|
|
return tcpresult
|
|
|
|
|
|
|
|
@@ -381,7 +390,12 @@ def netstat_udp4():
|
|
|
|
|
|
nline = '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('UDP4', l_host+': '+l_port, r_host+': '+r_port, udp_state, uid, pid, exe)
|
|
|
|
|
|
- udpresult.append(nline)
|
|
|
+ if o_reused == False:
|
|
|
+ if nline not in udpresult: # Hide multi binds on same Socket (SO_REUSEPORT)
|
|
|
+ udpresult.append(nline)
|
|
|
+ else:
|
|
|
+ udpresult.append(nline)
|
|
|
+
|
|
|
return udpresult
|
|
|
|
|
|
def netstat_udp6():
|
|
@@ -425,7 +439,12 @@ def netstat_udp6():
|
|
|
|
|
|
nline = '%-7s %-24s %-24s %-11s %-8s %-6s %-s' % ('UDP6', _compress_v6(_convert_ipv6(line_array[1]))+': '+l_port, _compress_v6(_convert_ipv6(line_array[2]))+': '+r_port, udp_state, uid, pid, exe)
|
|
|
|
|
|
- udpresult.append(nline)
|
|
|
+ if o_reused == False:
|
|
|
+ if nline not in udpresult: # Hide multi binds on same Socket (SO_REUSEPORT)
|
|
|
+ udpresult.append(nline)
|
|
|
+ else:
|
|
|
+ udpresult.append(nline)
|
|
|
+
|
|
|
return udpresult
|
|
|
|
|
|
|
|
@@ -491,10 +510,12 @@ if __name__ == '__main__':
|
|
|
o_tcp = True
|
|
|
o_v6 = True
|
|
|
o_v4 = True
|
|
|
- parser = argparse.ArgumentParser(description='netstat utility V'+VERSION+"\n2017-2019 by sigi <https://wiki.zweiernet.ch/wiki/sinetstat>",
|
|
|
+ o_reused = False
|
|
|
+ parser = argparse.ArgumentParser(description='netstat utility V'+VERSION+"\n2017-2022 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")
|
|
|
+ parser.add_argument('-s', help="Show all sockets on reused ports", action="store_true")
|
|
|
parser.add_argument('-r', help="Resolve IP-Addresses", action="store_true")
|
|
|
parser.add_argument('-w', help="Wide (show cmd)", action="store_true")
|
|
|
parser.add_argument('-W', help="Wider (show cmd with arguments)", action="store_true")
|
|
@@ -523,6 +544,8 @@ if __name__ == '__main__':
|
|
|
o_v6 = False
|
|
|
if args.v6:
|
|
|
o_v4 = False
|
|
|
+ if args.s:
|
|
|
+ o_reused = True
|
|
|
|
|
|
|
|
|
# Output
|