2016-10-06 8 views
1

Ich möchte tshark verwenden, um das Ziel oder die Quellen-IP zu finden, die nicht meins sind. Dazu verwende ich (ip-ifconfig gibt meine ip von ifconfig)Wie man ein Rohr nach tshark Funktion tshark Rohr hinzufügen

# tshark -T fields -e ip.addr -E aggregator=" " | sed "s/$(ip-ifconfig)//" 
tshark: Lua: Error during loading: 
[string "/usr/share/wireshark/init.lua"]:44: dofile has been disabled due to running Wireshark as superuser. See https://wiki.wireshark.org/CaptureSetup/CapturePrivileges for help in running Wireshark as an unprivileged user. 
Capturing on 'wlp3s0' 
**5500** 

ich die Anzahl der gefangenen Pakete bekommen. Ich möchte stattdessen die IPs.

Der Ausgang muss möglicherweise mit awk manipuliert werden.

Die Ausgabe dieses Befehls ohne das Rohr mit sed ist eine Liste von IPs

Antwort

1

Der Befehl sed "s/$(ip-ifconfig)//" nur mit dem leeren String Ihre IP-Adresse ersetzt. Dies ist wahrscheinlich nicht das, was Sie wollen. Außerdem kenne ich den ip-ifconfig-Befehl nicht, ich nehme an, er gibt Ihnen eine einzige IP-Adresse.

Eine einfache Möglichkeit, dies zu erreichen, wäre die Unterdrückung aller Zeilen, die Ihre IP-Adresse enthalten, z. Eines der folgenden zwei Beispiele:

tshark -T fields -e ip.addr -E aggregator=" " | grep -v "$(ip-ifconfig)" 
tshark -T fields -e ip.addr -E aggregator=" " | sed "/$(ip-ifconfig)/d" 

Diese Lösung ist jedoch nicht sehr robust. Wenn Ihre IP-Adresse 192.168.1.1 lautet, würde das obige Muster auch 192.168.1.10 oder 192.168.1.123 entsprechen. Sie können ein ganzes Wort mit den spitzen Klammern verbinden:

tshark -T fields -e ip.addr -E aggregator=" " | grep -vE "\<$(ip-ifconfig)\>" 
tshark -T fields -e ip.addr -E aggregator=" " | sed "/\<$(ip-ifconfig)\>/d" 

Dies sollte die meiste Zeit funktionieren. Beachten Sie, dass der Punkt in der IP-Adresse idealerweise maskiert sein sollte, andernfalls wird er als das Match-All-Zeichen im regulären Ausdruck verwendet.

Schließlich könnte man einfach die Anzeigefilter in tshark verwenden:

tshark -T fields -e ip.addr -E aggregator=" " -Y "ip.addr != $(ip-ifconfig)" 

Auf diese Weise können Sie ganz komplexe Filter aufzubauen.

1

Ich war auf der Suche nach tshark -l.

-l  Flush the standard output after the information for each packet is printed. (This is not, strictly speaking, line-buffered if -V was specified; however, it is the same as line- 
      buffered if -V wasn't specified, as only one line is printed for each packet, and, as -l is normally used when piping a live capture to a program or script, so that output for a 
      packet shows up as soon as the packet is seen and dissected, it should work just as well as true line-buffering. We do this as a workaround for a deficiency in the Microsoft 
      Visual C++ C library.) 

      This may be useful when piping the output of TShark to another program, as it means that the program to which the output is piped will see the dissected data for a packet as soon 
      as TShark sees the packet and generates that output, rather than seeing it only when the standard output buffer containing that data fills up.