Browse Source

V1.4 param -i no more mandatory, get it from standard route
subprocess import removed

Peter Siegrist 1 year ago
parent
commit
81ccc84da6
2 changed files with 17 additions and 13 deletions
  1. 4 4
      README.md
  2. 13 9
      sisniff

+ 4 - 4
README.md

@@ -42,7 +42,7 @@ Direct Download: `wget https://git.zweiernet.ch/sigi/sisniff/raw/master/sisniff`
 # sisniff -h
 usage: sisniff [-h] -i {eth0,lo,wlan0} [-n] [-p program|not-program] [-4] [-6] [-H] [-Hl] [filter]
 
-sisniff V1.3.1
+sisniff V1.4
 2017-2022 by sigi <https://wiki.zweiernet.ch/wiki/sisniff>
 
 positional arguments:
@@ -50,7 +50,7 @@ positional arguments:
 
 optional arguments:
   -h, --help            show this help message and exit
-  -i {eth0,lo,wlan0}    Interface (required)
+  -i {eth0,lo,wlan0}    Interface
   -n                    Do not resolve IP-Addresses
   -p program|not-program
                         Filter by program name (accepts * for matching) ([not-] negates)
@@ -70,8 +70,8 @@ optional arguments:
 
 ##### Example Commands
 <pre>
-# sisniff -i wlan0 "port not ssh"
-# sisniff -i wlan0 -p *vpn*
+# sisniff "port not ssh"
+# sisniff -p *vpn*
 # sisniff -i wlan0 -p not-thunderbird-bin -4 "host not www.zweiernet.ch"
 # sisniff -i eth0 -p firefox -Hl "port 80"		
 </pre>

+ 13 - 9
sisniff

@@ -23,10 +23,10 @@ import string
 import fcntl
 import struct
 import argparse
-if sys.version_info.major == 2:
-    import commands as subprocess
-elif sys.version_info.major == 3:
-    import subprocess
+#if sys.version_info.major == 2:
+#    import commands as subprocess
+#elif sys.version_info.major == 3:
+#    import subprocess
 
 def _to_str(inp):
     if sys.version_info.major == 2:
@@ -35,7 +35,7 @@ def _to_str(inp):
         return "".join( chr(x) for x in inp)
     
 
-VERSION = "1.3.1"
+VERSION = "1.4"
 
 PROC_TCP4 = "/proc/net/tcp"
 PROC_UDP4 = "/proc/net/udp"
@@ -453,15 +453,17 @@ if not check_root():
     sys.exit()
 
 # get the interfaces
-ifaces = subprocess.getoutput("ls /sys/class/net")
-iface_list = ifaces.split('\n')
+#ifaces = subprocess.getoutput("ls /sys/class/net")
+#iface_list = ifaces.split('\n')
+iface_list = get_if_list()
+iface = conf.route.route("0.0.0.0")[0]
 
 rfilter = "ip or ip6"
 print("")
 # commandline params
 parser = argparse.ArgumentParser(description='sisniff V'+VERSION+"\n2017-2022 by sigi <https://wiki.zweiernet.ch/wiki/sisniff>",
                                    formatter_class=argparse.RawDescriptionHelpFormatter)
-parser.add_argument('-i', help="Interface (required)", choices=iface_list, required=True)
+parser.add_argument('-i', help="Interface", choices=iface_list)
 parser.add_argument('-n', help="Do not resolve IP-Addresses", action="store_true")
 parser.add_argument('-p', help='Filter by program name (accepts * for matching) ([not-] negates)', type=str, metavar='program|not-program')
 parser.add_argument('-4', dest='v4', help="Only IPv4", action="store_true")
@@ -470,7 +472,8 @@ parser.add_argument('-H', help="Show HTTP Payload", action="store_true")
 parser.add_argument('-Hl', help="Show HTTP Payload, long output", action="store_true")
 parser.add_argument('filter', nargs='?', help="Filter (BPF syntax) on top of IP (in dbl-quotes \"...\")", type=str)
 args = parser.parse_args()
-iface = args.i
+if args.i:
+	iface = args.i
 if args.n:
     numeric = True
 if args.v4:
@@ -507,6 +510,7 @@ else:
 	MYADDRS = MYADDRS + MYADDRS6
 xMYADDRS = xMYADDRS + [_to_v6_proc(expand_v6(x)) for x in MYADDRS6]
 print("> My IP-Addresses: " + str(MYADDRS))
+print("> Listening on: " + iface)
 
 # confirmed connections cache (ringboffer)
 conn_cache = []