TShark
What is the purpose of TShark?
TShark is the command-line network protocol analyzer from the Wireshark project. It captures packets from network interfaces, reads packet capture files, applies Wireshark display filters, extracts protocol fields, and exports decoded packet data in automation-friendly formats.
TShark is useful because it brings Wireshark's dissectors and filtering language to terminals, servers, CI jobs, incident response workflows, and repeatable analysis scripts. It is commonly used for packet triage, protocol debugging, traffic extraction, forensics, malware lab analysis, and service-specific evidence collection.
Note: TShark has two different filter concepts. Use -f for capture filters that reduce what is captured at packet collection time. Use -Y for Wireshark display filters that select decoded packets while reading or printing results.
Here are the primary uses of TShark:
-
Live Packet Capture: TShark captures traffic from interfaces and writes it to
pcaporpcapngfiles for later analysis. -
Packet Capture Triage: The tool reads existing captures, applies display filters, and prints packet summaries or detailed protocol trees without opening Wireshark.
-
Field Extraction: TShark can extract selected fields such as source IP, destination IP, DNS query name, HTTP host, TLS SNI, frame time, and protocol-specific values.
-
Protocol-Specific Investigation: The tool supports Wireshark display filters for protocols such as DNS, HTTP, TLS, SMB, Kerberos, DHCP, SIP, MQTT, RADIUS, and many others.
-
Statistics and Conversation Analysis: TShark can generate protocol hierarchy, endpoint, conversation, I/O, and service response time statistics from capture files.
-
Automation and Reporting: The tool exports fields, JSON, Elastic-compatible JSON, PDML, PSML, tabs, and text output for scripts and pipelines.
-
Wireless and Monitor Mode Workflows: When supported by the adapter and operating system, TShark can capture in monitor mode for wireless packet analysis.
Core Features
- Command-line packet capture and PCAP analysis
- Wireshark display filters and protocol dissection
- Field extraction and structured output formats
- Interface, capture filter, ring buffer, and duration controls
- Conversation, endpoint, IO, and protocol statistics
- TLS key log and decode-as support
- Automation-friendly text, JSON, and EK output
Data sources
- Live network interfaces
- PCAP and PCAPNG capture files
- Packet headers, payloads, and protocol fields
- Capture and display filters
- TLS key log files and decode preferences
- Extracted fields, conversations, and statistics
Common TShark Commands
1. Install TShark with Homebrew
- This command installs Wireshark command-line tools on macOS through Homebrew.
brew install wireshark
2. Install TShark on Debian or Ubuntu
- This command installs TShark from apt repositories.
sudo apt install tshark
3. Check TShark Version
- This command prints the installed TShark and Wireshark library version information.
tshark --version