| Field | Detail |
|---|---|
| Summary | Scriptable CLI capture and field extraction for pipelines |
| Category | Traffic capture & analysis (CLI) |
| Phase | recon, analysis, post-exploitation |
| Interface | CLI |
| Platform | Linux, Windows, macOS |
| Licence | Open source (GPL) |
| Docs | https://www.wireshark.org/docs/man-pages/tshark.html |
| Related | Wireshark and tcpdump, Netcat, OSINT and recon |
Wireshark's command-line engine — the same dissectors and display-filter language as the GUI, but scriptable, headless and pipeable. Ideal on servers/jump hosts, for extracting fields to CSV/JSON, and for repeatable analysis in a pipeline. Reads and writes the same .pcap/.pcapng as Wireshark and tcpdump.
⚠️ Warning — Same capture rules as any sniffer Live capture needs root /
wiresharkgroup and only on in-scope networks (UK: RIPA/IPA). For analysis you don't need privileges — read a pcap someone captured.
Capture
tshark -D # list interfaces (index + name)
tshark -i eth0 # live capture to stdout
tshark -i eth0 -w cap.pcapng # write to file
tshark -i eth0 -c 100 # stop after 100 packets
tshark -i eth0 -a duration:60 # autostop: 60s (also filesize:1000 / files:5)
tshark -i eth0 -b filesize:100000 -b files:10 -w ring.pcapng # ring buffer
tshark -i eth0 -f "tcp port 80" # capture (BPF) filter — applied live
tshark -i eth0 -s 96 # snaplen (headers only)
tshark -i eth0 -p # no promiscuous mode
💡 Tip —
-fvs-Y-fis a capture (BPF) filter — same syntax as tcpdump, applied before capture.-Yis a display filter — full Wireshark syntax, applied after dissection. Keep your own SSH out with-f 'not port 22'.
Read & filter
tshark -r cap.pcapng # read a file
tshark -r cap.pcapng -Y 'http.request' # Wireshark display filter
tshark -r cap.pcapng -n # no name resolution (faster)
tshark -r cap.pcapng -t ad # absolute date timestamps (ud/dd/r/e…)
tshark -r cap.pcapng -2 -R 'tcp.analysis.retransmission' # two-pass (filters needing full state)
tshark -r cap.pcapng -c 20 -x # first 20 packets as hex + ASCII
Extract fields (the killer feature)
# Columns of named fields — great for CSV / further processing
tshark -r cap.pcapng -Y 'http.request' -T fields \
-e ip.src -e http.host -e http.request.uri -E header=y -E separator=,
# JSON / Elasticsearch / XML outputs
tshark -r cap.pcapng -Y dns -T json
tshark -r cap.pcapng -T ek > packets.ndjson # bulk-index friendly
tshark -r cap.pcapng -V # full packet detail (like Wireshark's tree)
tshark -r cap.pcapng -O http,dns # verbose for only these protocols
-E options: header=y, separator=,, quote=d, occurrence=f|l|a (first/last/all).
Statistics (-z, usually with -q)
tshark -r cap.pcapng -q -z io,phs # protocol hierarchy
tshark -r cap.pcapng -q -z conv,tcp # TCP conversations (top talkers)
tshark -r cap.pcapng -q -z endpoints,ip # per-IP totals
tshark -r cap.pcapng -q -z http,tree # HTTP request/response breakdown
tshark -r cap.pcapng -q -z dns,tree # DNS query/response stats
tshark -r cap.pcapng -q -z expert # Wireshark "expert info" warnings
tshark -r cap.pcapng -q -z follow,tcp,ascii,0 # reassemble TCP stream index 0
tshark -r cap.pcapng -q -z credentials # surface cleartext creds it recognises
tshark -r cap.pcapng -q -z io,stat,60,'COUNT(frames)frames' # 60s interval stats
Decode-as, protocol prefs, name resolution
tshark -r cap.pcapng -d tcp.port==8443,tls # force a port to be dissected as TLS
tshark -r cap.pcapng -o 'tls.keylog_file:keys.log' -Y http2 # decrypt TLS with a keylog
tshark -r cap.pcapng -N mntC # enable MAC/network/transport/concurrent DNS resolution
tshark -r cap.pcapng --export-objects http,./loot # carve transferred HTTP files
Discover field/protocol names
tshark -G fields | grep -i "http.request" # every field name you can use with -e/-Y
tshark -G protocols | less # all protocols tshark knows
tshark -G column-formats # built-in column types
Handy recipes
# HTTP creds / basic-auth headers
tshark -r cap.pcapng -Y 'http.authorization' -T fields -e http.host -e http.authorization
# TLS SNI (hostnames even when traffic is encrypted)
tshark -r cap.pcapng -Y 'tls.handshake.extensions_server_name' -T fields -e tls.handshake.extensions_server_name | sort -u
# Top DNS queries
tshark -r cap.pcapng -Y dns -T fields -e dns.qry.name | sort | uniq -c | sort -rn | head
# Cleartext FTP/Telnet/POP creds
tshark -r cap.pcapng -Y 'ftp.request.command=="USER" || ftp.request.command=="PASS"' -T fields -e ftp.request.arg
# OT/ICS field extraction (pairs with the OT sheets)
tshark -r ot.pcap -Y modbus -T fields -e modbus.func_code -e modbus.reference_num
Kill-chain usage
Recon
tshark -i eth0 -f "port 80" # live capture
Analysis
tshark -r cap.pcap -Y 'http.authorization' -T fields -e http.authorization
Post-exploitation
# on a pivot host: extract creds/fields from captured traffic
Where it fits
The CLI counterpart to Wireshark and tcpdump — reach for it on headless hosts, in scripts/CI, and whenever you need fields piped into sort/uniq/jq rather than a GUI. Capture with tcpdump or tshark itself, analyse here, and open anything that needs visual inspection in Wireshark. Field extraction feeds nicely into OSINT and recon triage and the OT protocol analysis.