tshark Usage Examples

Check out these great references as well:
 Our custom profiles repository for Wireshark
 Our Udemy course on Wireshark 
 Our Udemy course on Wireless Packet capture

As many of you know, tshark is the command-line version of Wireshark, designed for packet capture and deep protocol analysis without a graphical interface. It uses the same underlying dissection engine as Wireshark, which means it can decode hundreds of protocols with the same level of detail—but entirely from the terminal.

If you are a tshark beginner, look first here.

For more advanced tshark users, read on.


I often get asked for actual tshark usage examples, so here is a compiled list – think of it like a detailed cheat sheet:

tshark Objectivetshark Command
Available Interfacestshark -D
Helptshark -h
Capture on an Interfacetshark -i # (where # is the interface number from -D command above)
tshark -i ‘name’ (where ‘name’ is the interface name from -D command above)
Write capture to a filetshark -i # -w {path and file name}
Capture using a filtertshark -i # -f “filter text using BPF syntax”
example: tshark -i 5 -f “tcp port 80”
Generic Capture for an IP Addresstshark -R “ip.addr == 192.168.0.1″ -r /tmp/capture.pcapng
Ethernet address 00:08:15:00:08:15eth.addr == 00:08:15:00:08:15
Ethernet type 0×0806 (ARP)eth.type == 0×0806
Ethernet broadcasteth.addr == ff:ff:ff:ff:ff:ff
No ARPnot arp
IPv4 onlyip
IPv6 onlyip6
IPv4 address isn’t 192.168.0.1, don’t use != for this!!(ip.addr == 192.168.0.1)
IPX onlyipx
TCP onlytcp
UDP onlyudp
To include display filters in the command when examining a capture file-Y <display filter>
UDP port isn’t 53 (not DNS), don’t use != for this!!(tcp.port == 53)
TCP or UDP port is 80 (HTTP)tcp.port == 80 || udp.port == 80
HTTP Onlyhttp
No ARP and no DNSnot arp and not (udp.port == 53)
Non-HTTP and non-SMTP to/from 192.168.0.1not (tcp.port == 80) and not (tcp.port == 25) and ip.addr == 192.168.0.1
Creating a “;” separated file with “source IP” “destination IP” and “Destination Port” from all with SYN initiated connections, you can use following sample:
Use the options -T , -E and -e (see man pages for infos)
tshark -nn -r capturefile.dmp -T fields -E separator=’;’ -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport ‘(tcp.flags.syn == 1 and tcp.flags.ack == 0)’
Display http response codestshark -o “tcp.desegment_tcp_streams:TRUE” -i eth0 -R “http.response” -T fields -e http.response.code
Display Top 10 URLstshark -r capture.pcapng -R http.request -T fields -e http.host -e http.request.uri |
sed -e ‘s/?.*$//’ | sed -e ‘s#^(.*)t(.*)$#http://12#’ | sort | uniq -c | sort -rn | head
Display Source IP and MAC Address. (coma sep)tshark -i eth0 -nn -e ip.src -e eth.src -Tfields -E separator=, -R ip
Display Target IP and Mac Address (coma sep)tshark -i eth0 -nn -e ip.dst -e eth.dst -Tfields -E separator=, -R ip
Source and Target IPv4tshark -i eth0 -nn -e ip.src -e ip.dst -Tfields -E separator=, -R ip
Source and Target IPv6tshark -i eth0 -nn -e ip6.src -e ip6.dst -Tfields -E separator=, -R ip6
Source IP and DNS Querytshark -i eth0 -nn -e ip.src -e dns.qry.name -E separator=”;” -T fields port 53
Display only the Source and the Destination IPtshark -o column.format:’”Source”, “%s”,”Destination”, “%d”‘ -Ttext
Various Statistics from a capture: We suggest you play with some of these command to check out the various statistics the individual commands offer.
We use an example filename: capture.pcapng – just substitute this for the file name you want to analyze.
tshark -r capture.pcapng -qz io,stat,1,0,sum(tcp.analysis.retransmission)”ip.addr==10.10.10.10″ > stat.txt
tshark -r capture.pcapng -qz io,stat,120,”ip.addr==194.134.109.48 && tcp”,”COUNT(tcp.analysis.retransmission)ip.addr==194.134.109.48 && tcp.analysis.retransmission”
tshark -r capture.pcapng -qz io,stat,30,”COUNT(tcp.analysis.retransmission) tcp.analysis.retransmission”
tshark -r capture.pcapng -qz io,stat,30,
“COUNT(tcp.analysis.retranmission)tcp.analysis.retransmission”,
“AVG(tcp.window_size)tcp.window_sizeтАЭ,тАЭMAX(tcp.window_size)”,
“MIN(tcp.window_size)tcp.window_size”
tshark -r capture.pcapng -qz io,stat,5,”COUNT(tcp.analysis.retransmission) tcp.analysis.retransmission”,”COUNT(tcp.analysis.duplicate_ack)tcp.analysis.duplicate_ack”,
“COUNT(tcp.analysis.lost_segment) tcp.analysis.lost_segment”,
“COUNT(tcp.analysis.fast_retransmission) tcp.analysis.fast_retransmission”
tshark -r capture.pcapng -qz io,stat,5,”MIN(tcp.analysis.ack_rtt)tcp.analysis.ack_rtt”,
“MAX(tcp.analysis.ack_rtt)tcp.analysis.ack_rtt”,”AVG(tcp.analysis.ack_rtt)tcp.analysis.ack_rtt”
tshark -r capture.pcapng -qz ip_hosts,tree
tshark -r capture.pcapng -qz ptype,tree
Display all IP conversations in a capture filetshark -r capture.pcapng -qz conv,ip
Display all TCP conversations in a capture filetshark -r capture.pcapng -qz conv,tcp
Display the number of HTTP redirections in a capture filetshark -r capture.pcapng -Y “http.response.code in {300..399}” | wc -l
Display the users where an iphone has connected to the networktshark -r capture.pcapng -Y ‘lower(dhcp.option.hostname) contains “iphone” ‘ -T fields -e dhcp.option.hostname | sort -u
Display the average DNS response timetshark -r capture.pcapng -Y dns.time -T fields -e dns.time | awk ‘{sum+=$1;count+=1} END {printf(“%9.6fn”,sum/count)}’
Display the slowest DNS response timetshark -r nfl.pcapng -Y “dns.flags.response == 1 and dns.time” -T fields -e dns.time | sort -rn | head -1 | sed ‘s/0*$/ seconds/’
Display hosts that do not support SACKtshark -r capture.pcapng -Y “tcp.flags.syn==1 and (tcp.flags.ack==0 or (tcp.flags.ack == 1 and tcp.stream in {$( tshark -r capture.pcapng -Y “tcp.flags.syn==1 and tcp.flags.ack==0 and tcp.options.sack_perm” -T fields -e tcp.stream | sort -u | xargs ) 4294967295} ) ) and not tcp.options.sack_perm” -T fields -e ip.src

You will find other T-Shark articles by clicking here.

If you would like to help support the continued development of independent networking, broadband, Wi-Fi, VoIP, and packet analysis content, please consider joining our Patreon community where you will gain access to exclusive technical resources, downloadable labs and PCAPs, bonus course content, troubleshooting guides, and additional member-only material.  Comments and technical discussion are always welcomed at our Patreon community or on our Discord server.  You can also support our work by simply buying us a coffee — every contribution helps us continue creating practical, real-world network science education for professionals and enthusiasts alike.

Leave a Comment

Scroll to Top