tshark (2/2)
Part 2 of tshark turns a capture into answers: -z statistics build reports (protocol hierarchy, conversations, endpoints, HTTP/DNS trees, expert info, follow stream) instead of printing every packet. It also covers logging, help/version and the WIRESHARK_* environment variables. Lab: client 192.168.145.10 (tshark 4.2.4), server 192.168.145.20 (HTTP :80 + DNS :53).
125.1 Why is it used?
- Get an overview of an unknown pcap in seconds, without a GUI.
- Find top talkers, slow DNS, HTTP errors and TCP problems from a single report.
- Read a whole conversation as text with follow.
- Debug or reconfigure tshark itself with --log-*, -v and environment variables.
125.2 How it works
- Step 1
1.Client pings server 192.168.145.20 through the Docker bridge
- Step 2
2.Client asks DNS for web.lab; server answers 192.168.145.20 (nope.lab -> NXDOMAIN)
- Step 3
3.Client sends HTTP GET /hello.txt (200 OK) and /missing.txt (404)
- Step 4
4.tshark on client eth0 writes a copy of all 40 packets to lab.pcapng
- Step 1
1.tshark -r lab.pcapng -q -z io,phs
- Step 2
2.Every packet is read and dissected
- Step 3
3.Counters are updated per protocol / conversation / host
- Step 4
4.-q suppresses the per-packet list
- Step 5
5.Only the report is printed at the end
ICMP 6 frames, DNS 4, TCP 25 of which HTTP 4
125.3 The lab capture
- -a duration:20 stops the capture by itself after 20 seconds.
- Traffic: 3 pings, DNS for web.lab and nope.lab, curl for hello.txt and missing.txt.
tshark -i eth0 -a duration:20 \ -w /tmp/lab.pcapng &ping -c 3 -i 0.3 192.168.145.20 | tail -2dig +short @192.168.145.20 web.labdig @192.168.145.20 nope.lab | grep statuscurl -s http://192.168.145.20/hello.txtcurl -s -o /dev/null -w '%{http_code}\n' \ http://192.168.145.20/missing.txttshark -r /tmp/lab.pcapng | wc -l3 packets transmitted, 3 received, 0% packet loss$ dig +short @192.168.145.20 web.lab192.168.145.20$ dig @192.168.145.20 nope.lab | grep status;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN$ curl -s http://192.168.145.20/hello.txthello from n125 lab$ curl ... http://192.168.145.20/missing.txt40440 packets captured$ tshark -r /tmp/lab.pcapng | wc -l40125.4 Overview: io,phs and io,stat
- io,phs shows frames and bytes per protocol as a tree (eth > ip > tcp > http).
- io,stat,1 counts frames and bytes in every 1-second interval; add filters to make extra columns (io,stat,1,icmp,dns).
- Functions COUNT, SUM, MIN, MAX, AVG(field) give per-interval values.
tshark -r /tmp/lab.pcapng -q -z io,phstshark -r /tmp/lab.pcapng -q -z io,stat,1Protocol Hierarchy Statisticseth frames:40 bytes:3712 arp frames:5 bytes:210 ip frames:35 bytes:3502 icmp frames:6 bytes:588 udp frames:4 bytes:332 dns frames:4 bytes:332 tcp frames:25 bytes:2582 http frames:4 bytes:793$ tshark -r /tmp/lab.pcapng -q -z io,stat,1| Duration: 10.473793 secs || Interval | Frames | Bytes || 0 <> 1 | 9 | 714 || 1 <> 2 | 0 | 0 || 2 <> 3 | 2 | 173 || 4 <> 5 | 2 | 159 || 7 <> 8 | 12 | 1100 || 10 <> Dur| 13 | 1482 |125.5 Who talks to whom: conv and endpoints
- conv,ip: one line per IP pair (35 frames between client and server).
- conv,tcp: one line per TCP connection, so the two curl requests are two lines.
- endpoints,ip: per-host totals with Tx and Rx columns; the server sent more bytes (HTTP responses).
- Other types: eth, ipv6, udp, sctp, wlan; add a display filter at the end (conv,tcp,ip.addr==X).
tshark -r /tmp/lab.pcapng -q -z conv,iptshark -r /tmp/lab.pcapng -q -z conv,tcptshark -r /tmp/lab.pcapng -q -z endpoints,ipIPv4 Conversations | <- | | -> | | Total |192.168.145.10 <-> 192.168.145.20 16 1913 bytes 19 1589 bytes 35 3502 bytesTCP Conversations192.168.145.10:35358 <-> 192.168.145.20:80 6 924 bytes 7 558 bytes 13 1482 bytes192.168.145.10:35342 <-> 192.168.145.20:80 5 544 bytes 7 556 bytes 12 1100 bytesIPv4 Endpoints| Packets | | Bytes | | Tx Packets | | Tx Bytes | | Rx Packets | | Rx Bytes |192.168.145.10 35 3502 19 1589 16 1913192.168.145.20 35 3502 16 1913 19 1589125.6 Application stats: http,tree and dns,tree
tshark -r /tmp/lab.pcapng -q -z http,treetshark -r /tmp/lab.pcapng -q -z dns,treeHTTP/Packet Counter:Topic / Item CountTotal HTTP Packets 4 HTTP Response Packets 2 4xx: Client Error 1 404 Not Found 1 2xx: Success 1 200 OK 1 HTTP Request Packets 2 GET 2DNS:Topic / Item CountTotal Packets 4 rcode 4 No error 3 No such name 1 Response 2 Query 2 request-response time (msec) 2 Average 0.46 Min 0.238075 Max 0.679701125.7 Expert info
- Wireshark's built-in doctor: chats, notes, warnings and errors for every packet.
- This clean capture has only chats and notes (SYN, FIN, HTTP request lines).
- On a real network expert puts retransmissions, resets and zero window at the top; expert,warn shows warning and above.
tshark -r /tmp/lab.pcapng -q -z expertNotes (4) 2 Sequence TCP This frame initiates the connection closing 2 Sequence TCP This frame undergoes the connection closingChats (12) 2 Sequence TCP Connection establish request (SYN) 2 Sequence TCP ... acknowledge (SYN+ACK) 1 Sequence HTTP GET /hello.txt HTTP/1.1\r\n 1 Sequence HTTP HTTP/1.0 200 OK\r\n 4 Sequence TCP Connection finish (FIN) 1 Sequence HTTP GET /missing.txt HTTP/1.1\r\n 1 Sequence HTTP HTTP/1.0 404 File not found\r\n125.8 Follow a stream
- follow,tcp,ascii,0 reassembles TCP stream 0 and prints it as text.
- Node 0 is the client, Node 1 the server; numbers like 86/186/20 are byte counts.
- Also udp, tls (if decrypted), http, http2, quic; modes ascii, hex, raw, utf-8; flow draws an ASCII sequence diagram.
tshark -r /tmp/lab.pcapng -q -z follow,tcp,ascii,0Follow: tcp,asciiFilter: tcp.stream eq 0Node 0: 192.168.145.10:35342Node 1: 192.168.145.20:8086GET /hello.txt HTTP/1.1Host: 192.168.145.20User-Agent: curl/8.7.1 186HTTP/1.0 200 OKServer: SimpleHTTP/0.6 Python/3.12.3Content-type: text/plainContent-Length: 20 20hello from n125 lab125.9 All -z statistics at a glance
| -z stat | What it answers | Lab result |
|---|---|---|
| io,phs | Which protocols are in the capture? | icmp 6, dns 4, tcp 25 (http 4) frames |
| io,stat,1 | Frames/bytes per interval (custom columns: COUNT, SUM, AVG...) | Second 7-8: 12 frames (first HTTP request) |
| conv,ip / conv,tcp | Who talks to whom; one line per connection | 35 frames .10 <-> .20; two TCP conns to :80 |
| endpoints,ip | Per-host totals, Tx/Rx | .20 Tx 1913 bytes, .10 Tx 1589 bytes |
| http,tree | Status codes and methods | 2 GET: one 200 OK, one 404 |
| dns,tree | rcodes and response time | 3 No error, 1 No such name, avg 0.46 ms |
| expert | Notes, warnings, errors (retransmissions, resets, zero window) | Only chats + notes: clean capture |
| follow,tcp,ascii,N | Reassembled stream as text | GET /hello.txt and the 200 OK body |
| icmp,srt / rtp,streams | Ping RTT / VoIP jitter + loss | (not run) |
- -z help lists every available stat (176 names in this build), so there is no need to memorise them.
- Protocol-specific groups: smb,srt, radius,rtd, dcerpc,srt (response times), gtp/gsm/camel (mobile), sip,stat, bacapp/someip (industrial, car).
tshark -z help 2>&1 | wc -ltshark -z help 2>&1 | head -4$ tshark -z help 2>&1 | wc -l177$ tshark -z help 2>&1 | head -4tshark: The available statistics for the "-z" option are: afp,srt ancp,tree ansi_a,bsmap125.10 Logging, help and version
- --log-level debug shows what tshark does inside (13 'Plugins' lines while loading plugins).
- --log-domains '!Plugins' removes a domain; --log-file writes the logs to a file.
- -h prints all options (166 lines); -v shows the build: libpcap, GnuTLS, nghttp2, Lua or not. Paste -v into every bug report.
tshark -r /tmp/lab.pcapng -c 1 \ --log-level debug 2>&1 | grep -c Pluginstshark -r /tmp/lab.pcapng -c 1 \ --log-level debug --log-domains '!Plugins'tshark -r /tmp/lab.pcapng -c 1 \ --log-level info --log-file /tmp/ts.log \ > /dev/null 2>&1wc -l < /tmp/ts.log$ ... --log-level debug 2>&1 | grep -c Plugins13$ ... --log-level debug --log-domains '!Plugins' 1 0.000000000 c2:2f:51:1a:47:92 → Broadcast ARP 42 Who has 192.168.145.20? Tell 192.168.145.10$ wc -l < /tmp/ts.log13tshark -h | wc -ltshark -v | head -1tshark -v | grep -iE 'with |Running' | head -4$ tshark -h | wc -l166$ tshark -v | head -1TShark (Wireshark) 4.2.4 (Git commit c966d79150b6).$ tshark -v | grep -iE 'with |Running' | head -4Compiled (64-bit) using GCC 13.2.1 20240309,with GLib 2.78.4, with libpcap,with POSIX capabilities (Linux), with libnl 3,without Lua, with GnuTLS 3.8.3 and PKCS #11125.11 Environment variables
- WIRESHARK_CONFIG_DIR moved the personal config folder to /tmp/wsconf.
- A hosts file there named 192.168.145.20 as web.lab, so -N n shows web.lab instead of the IP.
- On Windows CMD set them with: set WIRESHARK_CONFIG_DIR=C:\wsconf
WIRESHARK_CONFIG_DIR=/tmp/wsconf \ tshark -G folders | grep -i 'Personal config'cat /tmp/wsconf/hoststshark -r /tmp/lab.pcapng -n -Y icmp | head -2WIRESHARK_CONFIG_DIR=/tmp/wsconf \ tshark -r /tmp/lab.pcapng -N n -Y icmp | head -2$ tshark -G folders | grep -i 'Personal config' (default)Personal configuration: /root/.config/wireshark$ WIRESHARK_CONFIG_DIR=/tmp/wsconf tshark -G folders ...Personal configuration: /tmp/wsconf$ cat /tmp/wsconf/hosts192.168.145.20 web.lab$ tshark -r /tmp/lab.pcapng -n -Y icmp | head -24 0.000056742 192.168.145.10 → 192.168.145.20 ICMP5 0.000119488 192.168.145.20 → 192.168.145.10 ICMP$ WIRESHARK_CONFIG_DIR=/tmp/wsconf tshark ... -N n4 0.000056742 192.168.145.10 → web.lab ICMP5 0.000119488 web.lab → 192.168.145.10 ICMP| Variable / option | Effect |
|---|---|
| WIRESHARK_CONFIG_DIR | Personal config folder (hosts, profiles, prefs) |
| WIRESHARK_DATA_DIR / PLUGIN_DIR / EXTCAP_DIR | Load data files, plugins, extcap programs from another folder |
| WIRESHARK_LOG_LEVEL / LOG_DOMAINS / LOG_FATAL | Same as --log-level / --log-domains / --log-fatal |
| WIRESHARK_ABORT_ON_DISSECTOR_BUG | Abort on dissector bugs (for developers) |
| --log-level noisy|debug|info|message|warning|critical|error | How much tshark logs about itself |
| --log-domains '!Plugins' / --log-file path | Filter log domains (! inverts) / write logs to a file |
125.12 Common mistakes
- Treating a -z report as the truth about the whole network: it only counts what that interface saw.
- Capture stopped too early, so http,tree shows zero: check capture point and duration first.
- Forgetting -q: the packet list scrolls over the report.
- Expecting follow,tls to show plaintext without TLS keys.
125.13 Interview tips
- Quick pcap triage: -q -z io,phs (protocols) -> conv,tcp / endpoints,ip (top talkers) -> expert (problems) -> follow,tcp,ascii,N (content).
- Top talker = endpoints,ip, Tx Bytes column.
- dns,tree gives rcode counts and request-response time; http,tree gives status code counts.
- All of it works headless, so it fits servers and CI scripts.