| name | tshark |
| description | Analyze network packets using tshark (Wireshark CLI). Use when the user wants to capture live traffic, read .pcap/.pcapng files, filter packets by protocol or field, extract specific fields, drill into packet details, or generate traffic statistics. Covers live capture, pcap file analysis, display filters, field extraction, protocol drill-down, conversation stats, flow analysis, and JSON/PDML output for programmatic processing. |
| compatibility | Requires tshark (Wireshark) installed. On CentOS/RHEL use `dnf install wireshark-cli`. Live capture requires root or CAP_NET_RAW. Reading pcap files works as any user. |
| allowed-tools | Bash |
| metadata | {"author":"xtf","version":"1.0","reference":"https://www.wireshark.org/docs/man-pages/tshark.html"} |
tshark Packet Analysis Skill
tshark is the command-line interface for Wireshark — the industry-standard network protocol analyzer. It supports live capture, reading pcap/pcapng files, deep protocol dissection, field extraction, and rich statistics.
Step 1 — Determine the analysis mode
| Mode | Scenario | Key option |
|---|
| Read pcap file | Analyze an existing capture | -r <file> |
| Live capture | Capture from a live interface | -i <iface> (requires root) |
| Pipe input | Read from stdin | -r - |
Always prefer reading a file when one is available — no privilege required and fully repeatable.
tshark -D
tshark -r capture.pcap
tshark -r capture.pcap.gz
Step 2 — Apply display filters (-Y)
Display filters are Wireshark syntax and are extremely powerful. Use -Y when reading a file or capturing live.
tshark -r capture.pcap -Y "http"
tshark -r capture.pcap -Y "dns"
tshark -r capture.pcap -Y "tcp"
tshark -r capture.pcap -Y "ip.addr == 192.168.1.1"
tshark -r capture.pcap -Y "ip.src == 10.0.0.1 && ip.dst == 10.0.0.2"
tshark -r capture.pcap -Y "tcp.port == 443"
tshark -r capture.pcap -Y "udp.port == 53"
tshark -r capture.pcap -Y "tcp.port == 80 || tcp.port == 443"
tshark -r capture.pcap -Y "http && ip.addr == 10.0.0.5"
tshark -r capture.pcap -Y "tcp.flags.syn == 1 && tcp.flags.ack == 0"
tshark -r capture.pcap -Y 'dns.qry.name contains "example.com"'
tshark -r capture.pcap -Y "http.response.code >= 400"
tshark -r capture.pcap -Y "icmp.type == 3"
Capture filters vs display filters: -f uses libpcap/BPF syntax (faster, for live capture only). -Y uses Wireshark display filter syntax (more powerful, works on files and live). Do not mix them — they are different languages.
Step 3 — Drill into packet details
View full packet decode (-V)
Shows all protocol layers and every field value.
tshark -r capture.pcap -V
tshark -r capture.pcap -Y "dns" -V
tshark -r capture.pcap -O http
tshark -r capture.pcap -O http,tcp
tshark -r capture.pcap -Y "http" -O http
tshark -r capture.pcap -P -V -Y "tcp.flags.syn == 1"
Two-pass analysis (-2)
Enables cross-packet fields like "response in frame #" and better reassembly. Always use for file analysis when investigating request/response pairs.
tshark -r capture.pcap -2 -Y "http" -V
Inspect a specific packet by frame number
tshark -r capture.pcap -Y "frame.number == 42" -V
Step 4 — Extract specific fields (-T fields -e)
Extract structured data for scripting or reporting. Field names use Wireshark dot-notation.
tshark -r capture.pcap -T fields -e frame.number -e frame.time -e ip.src -e ip.dst -e _ws.col.info
tshark -r capture.pcap -T fields -E header=y -e ip.src -e ip.dst -e tcp.srcport -e tcp.dstport
tshark -r capture.pcap -Y "dns.flags.response == 0" \
-T fields -E header=y \
-e frame.time -e ip.src -e dns.qry.name -e dns.qry.type
tshark -r capture.pcap -Y "http.request" \
-T fields -E header=y \
-e ip.src -e ip.dst -e http.host -e http.request.method -e http.request.uri
tshark -r capture.pcap -Y "tls.handshake.type == 1" \
-T fields -e ip.src -e ip.dst -e tls.handshake.extensions_server_name
tshark -r capture.pcap -Y "tcp.flags.syn == 1 && tcp.flags.ack == 0" \
-T fields -e frame.time -e ip.src -e ip.dst -e tcp.dstport
tshark -r capture.pcap -T fields -e @ip.src -e @tcp.payload
Field separator options (-E):
-E separator=/t
-E separator=/s
-E separator=","
-E header=y
-E quote=d
-E occurrence=f
-E occurrence=a
Step 5 — Output formats (-T)
| Format | Use case |
|---|
-T text | Human-readable summary (default) |
-T fields | Structured field extraction (with -e) |
-T json | Full JSON decode, ideal for programmatic parsing |
-T pdml | XML format, full protocol detail |
-T ek | ElasticSearch/Kibana bulk JSON |
-T tabs | Tab-separated summary |
tshark -r capture.pcap -Y "dns" -T json
tshark -r capture.pcap -Y "frame.number == 10" -T json
tshark -r capture.pcap -Y "icmp" -T pdml
Step 6 — Statistics and flow analysis (-z)
-z generates statistical summaries. Use -q to suppress per-packet output and show only stats.
tshark -r capture.pcap -q -z io,phs
tshark -r capture.pcap -q -z conv,ip
tshark -r capture.pcap -q -z conv,tcp
tshark -r capture.pcap -q -z conv,udp
tshark -r capture.pcap -q -z endpoints,ip
tshark -r capture.pcap -q -z endpoints,tcp
tshark -r capture.pcap -q -z http,tree
tshark -r capture.pcap -q -z dns,tree
tshark -r capture.pcap -q -z follow,tcp,ascii,0
tshark -r capture.pcap -q -z follow,http,ascii,0
tshark -r capture.pcap -q -z follow,udp,ascii,0
tshark -r capture.pcap -q -z io,stat,1
tshark -r capture.pcap -q -z io,stat,0.1,"ip.src==10.0.0.1"
tshark -r capture.pcap -q -z expert
tshark -r capture.pcap -q -z sip,stat
See references/statistics.md for full -z option reference.
Step 7 — Live capture
tshark -i eth0 -c 100
tshark -i eth0 -f "tcp port 80" -w /tmp/http.pcap
tshark -i eth0 -P -V -f "icmp"
tshark -i eth0 -a duration:60 -w /tmp/capture.pcap
tshark -i eth0 -a filesize:10240 -w /tmp/capture.pcap
tshark -i eth0 -a packets:1000 -w /tmp/capture.pcap
tshark -i eth0 -b filesize:10240 -b files:5 -w /tmp/ring.pcap
Step 8 — Protocol-specific drill-down patterns
See references/protocols.md for ready-to-use filter and field recipes per protocol.
Quick reference — common protocols
| Protocol | Display filter | Key fields |
|---|
| DNS | dns | dns.qry.name, dns.qry.type, dns.resp.addr |
| HTTP | http | http.host, http.request.uri, http.response.code |
| TLS/HTTPS | tls | tls.handshake.extensions_server_name, tls.record.version |
| DHCP | dhcp | dhcp.option.hostname, dhcp.option.requested_ip_address |
| ICMP | icmp | icmp.type, icmp.code |
| ARP | arp | arp.src.hw_mac, arp.src.proto_ipv4 |
| OSPF | ospf | ospf.msg, ospf.srcrouter |
| BGP | bgp | bgp.type, bgp.prefix_length |
| SNMP | snmp | snmp.name, snmp.value |
| STP | stp | stp.root.hw, stp.bridge.hw |
| VLAN | vlan | vlan.id, vlan.priority |
| MPLS | mpls | mpls.label, mpls.ttl |
Step 9 — Discover field names
When you need the exact field name for filtering or -e extraction:
tshark -G protocols | grep -i "http"
tshark -G fields | grep "^F" | awk -F'\t' '$5=="http"'
tshark -G fields | grep -i "dns.qry"
tshark -G fields | grep -i "tls.handshake"
tshark -G fields | awk -F'\t' '$5=="tcp" {print $3, $2}'
Common workflows for the NOC agent
tshark -r capture.pcap -q -z io,phs
tshark -r capture.pcap -q -z conv,ip | sort -k1 -rn | head -20
tshark -r capture.pcap -Y "tcp.analysis.retransmission" -T fields \
-E header=y -e frame.time -e ip.src -e ip.dst -e tcp.stream
tshark -r capture.pcap -Y "icmp.type == 3" -V
tshark -r capture.pcap -Y "dns.flags.rcode == 3" \
-T fields -e frame.time -e ip.src -e dns.qry.name
tshark -r capture.pcap -q -z follow,tcp,ascii,<stream_index>
tshark -r capture.pcap -T fields -e ip.dst | sort -u
tshark -r capture.pcap -T fields -e ip.src | sort | uniq -c | sort -rn
tshark -r capture.pcap -Y "frame.len > 1400" -T fields \
-e frame.number -e frame.len -e ip.src -e ip.dst
tshark -r capture.pcap -q -z expert
Error handling
| Error | Cause | Fix |
|---|
permission denied on capture | No root / no CAP_NET_RAW | Run as root or sudo setcap cap_net_raw+eip $(which tshark) |
tshark: command not found | Not installed | dnf install wireshark-cli (CentOS/RHEL) |
The file "x" doesn't exist | Wrong path | Check path; use ls -la to verify |
| Filter syntax error | Wrong filter syntax | Check with tshark -Y "..." --dry-run or use -G fields to verify field names |
| Empty output | Filter too restrictive | Relax filter; check packet count with `tshark -r file.pcap |