Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting tshark output

Right now I'm using

tshark -i wlan0 -c 10 -T fields -e ip.src -e ip.dst -e ip.proto -e tcp.srcport -e tcp.dstport -e udp.srcport -e udp.dstport > test.txt

Which is working okay it gives me an output like:

192.168.1.240   198.38.110.157  6       50735   80              
198.38.110.157  192.168.1.240   6       80      50735           
192.168.1.240   198.38.110.157  6       50735   80              
198.38.110.157  192.168.1.240   6       80      50735           
192.168.1.240   198.38.110.157  6       50735   80              
198.38.110.157  192.168.1.240   6       80      50735           
192.168.1.240   198.38.110.157  6       50735   80              
198.38.110.157  192.168.1.240   6       80      50735           
192.168.1.240   198.38.110.157  6       50735   80              
198.38.110.157  192.168.1.240   6       80      50735 

Pretty cool, but is there anyone to get a nice simple stack like this for EVERY protocol? Just a simple tab delimited field I cannot seem to find this option in the tshark man page.

like image 547
Ricky Avatar asked Sep 25 '14 22:09

Ricky


1 Answers

You can try to use the -o option of tshark to format the output of tshark.

For instance,

tshark.exe -o "gui.column.format:\"Source\",\"%us\",\"Destination\",\"%ud\",\"src port\",\"%S\",\"dest port\",\"%D\"" -r sample_001.cap.pcapng

result:

10.191.144.161 → 10.210.62.164 57434 8888
10.191.144.161 → 10.210.62.164 57434 8888
10.210.62.164 → 10.191.144.161 8888 57434

(then, you just need to remove the "→")

To view the complete list of output fields that you can select, use the command tshark.exe -G column-formats:

c:\Program Files\Wireshark>tshark.exe -G column-formats
%q      802.1Q VLAN id
%Yt     Absolute date, as YYYY-MM-DD, and time
%YDOYt  Absolute date, as YYYY/DOY, and time
%At     Absolute time
%V      Cisco VSAN
%B      Cumulative Bytes
%Cus    Custom
%y      DCE/RPC call (cn_call_id / dg_seqnum)
%Tt     Delta time
%Gt     Delta time displayed
%rd     Dest addr (resolved)
%ud     Dest addr (unresolved)
%rD     Dest port (resolved)
%uD     Dest port (unresolved)
%d      Destination address
%D      Destination port
%a      Expert Info Severity
%I      FW-1 monitor if/direction
%F      Frequency/Channel
%hd     Hardware dest addr
%hs     Hardware src addr
%rhd    Hw dest addr (resolved)
%uhd    Hw dest addr (unresolved)
%rhs    Hw src addr (resolved)
%uhs    Hw src addr (unresolved)
%e      IEEE 802.11 RSSI
%x      IEEE 802.11 TX rate
%f      IP DSCP Value
%i      Information
%rnd    Net dest addr (resolved)
%und    Net dest addr (unresolved)
%rns    Net src addr (resolved)
%uns    Net src addr (unresolved)
%nd     Network dest addr
%ns     Network src addr
%m      Number
%L      Packet length (bytes)
%p      Protocol
%Rt     Relative time
%s      Source address
%S      Source port
%rs     Src addr (resolved)
%us     Src addr (unresolved)
%rS     Src port (resolved)
%uS     Src port (unresolved)
%E      TEI
%Yut    UTC date, as YYYY-MM-DD, and time
%YDOYut UTC date, as YYYY/DOY, and time
%Aut    UTC time
%t      Time (format as specified)

For example, to print Wireshark's default columns with tshark:

tshark.exe -o "gui.column.format:\"No.\",\"%m\",\"Time\",\"%t\",\"Source\",\"%s\",\"Destination\",\"%d\",\"Protocol\",\"%p\",\"Length\",\"%L\",\"Info\",\"%i\""

c:\Program Files\Wireshark>

like image 107
PPO Avatar answered Oct 05 '22 08:10

PPO