Tshark - TShark is
the command-line version of Wireshark
It performs similar network packet capture and analysis
functions but without a graphical user interface. It is widely
used for network monitoring, troubleshooting, and security analysis,
especially in environments where a GUI is not available.
Examples :
Capture packets on an interface:
tshark -i eth0
Capture and display only HTTP traffic:
tshark -i eth0 -f "tcp port 80"
Capture packets and save to a file:
tshark -i eth0 -w capture.pcap
Display DNS queries:
tshark -i eth0 -Y "dns"
Output capture to JSON format:
tshark -i eth0 -T json
Key Options:
-i -> interface selection : Specifies the network interface to capture packets
-D -> Get list of interfaces : we get output , that you get all list of interfaces
-f -> capture filter : Specifies a filter for the packets captured at the
interface level.
-Y -> display filter : Filters the packets after capture (similar to
Wireshark's display filters).
-w -> write output to the file: Writes the captured packets to a file
in PCAP format, which can be opened later in
Wireshark.
-r -> Read from file : Reads a PCAP file and displays its contents.
Example : tshark -r capture.pcap
-T -> Output Format : Specifies the output format for the captured data. Common options
include text, json, xml, or fields.
-e -> Display Fields : Displays specific fields from the packet data. You can use multiple -e
options to display multiple fields.
-c -> Set Output Limit : Captures a specific
number of packets before stopping.
Example : tshark -i eth0 -c 100
-f -> Capture on a Specific Port : Capture only packets on a specific port.
-z -> Show Statistics : Displays different kinds of statistics about the capture, such as packet
summaries, protocol hierarchies, or flow data.
-t -> Print Timestamp : Controls how timestamps are displayed. Common values are a (absolute), d
(delta), r (relative), u (unix time), etc
-B -> Sets the packet buffer size for capturing packets.
Example : tshark -B 10
-n -> Disable Name Resolution : Prevents TShark from resolving IP addresses to hostnames, which
can speed up the capture.
Example : tshark -i eth0 -n
-V -> Show Only Summary : Displays detailed packet information (verbose output).
Example : tshark -i eth0 -V
-z protos -> Show Protocol Hierarchy : Displays the protocol hierarchy from the capture.
Example : tshark -i eth0 -z protos
-A and -B -> Filter by Time (-A and -B) :
-A: Used for capturing traffic
for a specific time duration in seconds.
-B: Allows specifying a time duration for stopping the capture.
Example : tshark -i eth0 -A 30 -B 1000
Most used Tshark Field Names:
Here are some commonly used TShark field names
(tags) for different protocols:
1. Ethernet
- eth.src —
Source MAC address
- eth.dst —
Destination MAC address
- eth.type —
Ethernet type field
2. IP (Internet Protocol)
- ip.src —
Source IP address
- ip.dst —
Destination IP address
- ip.ttl —
Time to Live (TTL)
- ip.len —
Total length of the IP packet
3. TCP (Transmission Control
Protocol)
- tcp.srcport —
Source TCP port
- tcp.dstport —
Destination TCP port
- tcp.flags —
TCP flags (SYN, ACK, etc.)
- tcp.seq —
Sequence number
- tcp.ack —
Acknowledgment number
4. UDP (User Datagram Protocol)
- udp.srcport —
Source UDP port
- udp.dstport —
Destination UDP port
- udp.length —
Length of the UDP datagram
5. HTTP (Hypertext Transfer
Protocol)
- http.request.method —
HTTP request method (GET, POST, etc.)
- http.host —
Host header field
- http.user_agent —
User-Agent string
- http.response.code —
HTTP response status code
6. DNS (Domain Name System)
- dns.qry.name —
DNS query name
- dns.qry.type —
DNS query type
- dns.resp.name —
DNS response name
- dns.a —
DNS A record (IPv4 address)
7. ARP (Address Resolution
Protocol)
- arp.src.proto_ipv4 —
Sender's IPv4 address
- arp.dst.proto_ipv4 —
Target's IPv4 address
- arp.opcode —
ARP operation (1 = Request, 2 = Reply)
8. ICMP (Internet Control
Message Protocol)
- icmp.type —
ICMP type
- icmp.code —
ICMP code
- icmp.seq —
ICMP sequence number
9. TLS/SSL
- ssl.handshake.version —
SSL/TLS version
- ssl.record.version —
Record layer version
- ssl.handshake.type —
Handshake message type
10. General Packet Info
- frame.number —
Frame number in the capture
- frame.time —
Timestamp of the frame
- frame.len —
Length of the frame
- frame.protocols —
List of protocols in the frame