Networking/Computing Tips/Tricks

As many of you know, T-Shark is the command line version of Wireshark.  For T-Shark beginners, look first here.

For more advanced T-Shark users, read on.

I often get asked for T-Shark usage examples, so here is a compiled list - think of it like a detailed cheat sheet:

T-Shark Objective T-Shark Command
Available Interfaces tshark -D
Help tshark -h
Capture on an Interface tshark -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 file tshark -i # -w {path and file name}
Capture using a filter

tshark -i # -f "filter text using BPF syntax"
example: tshark -i 5 -f "tcp port 80"

Generic Capture for an IP Address

tshark -R “ip.addr == 192.168.0.1″ -r /tmp/capture.pcapng

Ethernet address 00:08:15:00:08:15 eth.addr == 00:08:15:00:08:15
Ethernet type 0×0806 (ARP) eth.type == 0×0806
Ethernet broadcast eth.addr == ff:ff:ff:ff:ff:ff
No ARP not arp
IP only ip
IP address isn't 192.168.0.1, don't use != for this! !(ip.addr == 192.168.0.1)
IPX only ipx
TCP only tcp
UDP only udp
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 Only http
No ARP and no DNS not arp and not (udp.port == 53)
Non-HTTP and non-SMTP to/from 192.168.0.1 not (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 codes

tshark -o “tcp.desegment_tcp_streams:TRUE” -i eth0 -R “http.response” -T fields -e http.response.code
Display Top 10 URLs

tshark -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 IPv4 tshark -i eth0 -nn -e ip.src -e ip.dst -Tfields -E separator=, -R ip
Source and Target IPv6 tshark -i eth0 -nn -e ip.dst -e ip.dst -Tfields -E separator=, -R ip
Source IP and DNS Query tshark -i eth0 -nn -e ip.src -e dns.qry.name -E separator=”;” -T fields port 53
Display only the Source and the Destination IP tshark -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 samples.cap -q -z io,stat,30,”COUNT(tcp.analysis.retransmission) tcp.analysis.retransmission”

tshark -r capture.pcapng -q -z 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 -q -z 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 -q -z 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 -q -z ip_hosts,tree

tshark -r capture.pcapng -q -z conv,tcp

tshark -r capture.pcapng -q -z ptype,tree

 

Hope this helps.

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

Comments powered by CComment

Find by Tag

4G Networks 5G Networks 6LoWLAN 6LoWPAN 802.11 802.11ah 802.11ax 802.11ay 802.11az Ad-Hoc Addressing Analysis Ansible Architecture ARP Assessment AToM Automation Baseline BGP Bloom's Taxonomy Cable cat CellStream Cellular Central Office Cheat Sheet Chrome Cisco Cloud CMD Computer Consulting Data Center Data Networking Dependencies DHCPv6 DNS Docker Documentation Dublin-Traceroute dumpcap Earth Earthquakes ECMP Ethernet Ethics Etiquette Evaluation Field Operations Fragmentation G-MPLS Gauge GeoIP GNS3 Google GQUIC Hands-On History Home Network ICMP ICMPv6 IEEE 802.11p IEEE 802.15.4 India Internet IoT IPsec IPv4 IPv6 IRINN IS-IS L2VPN L3VPN LDP LifeNet Linux LLN LoL M-BGP MAC Macro Microsoft mininet Monitoring MPLS mtr MTU Multicast Murphy Name Resolution Netcat NetMon netsh Networking nmap NSE Observations Online School OpenFlow OSPF OSPFv2 OSPFv3 OSX OTT Paris-Traceroute Parrot PIM PMTU Policy POTS POTS to Pipes PPP Profile Project Management PW3E QoS QUIC Railroad Remote Desktop Requirements Resume Review RIP Routing RPL RSVP Rural SDN Security Service Provider Small Business SONET Speed SSH SSL Status Storms Subnetting SYSCTL T-Shark TCP TCP/IP Telco Telecom 101 Telecommunications Telephone Testing TLS Tools Traceroute Traffic Engineering Training Travel Tunnel Ubuntu Utility Video Virtualbox Virtualization VoIP VRF VXLAN Wi-Fi Wi-Fi 4 Wi-Fi 5 Wi-Fi 6 Windows Wireless Wireless 5G Wireshark WLAN Writing Zenmap ZigBee

Twitter Feed