tshark是wireshark
网络分析工具下的一个分支,主要用于命令行环境进行抓包、分析,尤为对协议深层解析时,tcpdump
难以胜任的场景中。本系列文章将整理介绍tshark相关内容。html
tshark -v
tshark -D
网卡描述依据OS有不一样的编号方式,在不了解网络设备及编号状况下,通常先用“tshark -D”查看网络接口的编号以供-i参数使用。
注: linux能够结合ifconfig命令查看
sudo tshark -i <interface>
tshark -i eth0 -w capture123.pcap
tshark -i eth0 -r capture123.pcap
tshark -i eth0 -a duration:600
注: 默认时间单位为秒mysql
tshark -c 10000 -i eth0
tshark -i eth0 -f “host 192.168.1.1”
注: 与wireshark、tcpdump一致,均使用BPF过滤表达式
tshark -i eth0 -f “<协议名>”
协议名能够为: tcp, udp, dns, icmp, http等
tshark -s 512 -i eth1 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query
说明:linux
tshark -s 512 -i eth1 -n -f 'tcp dst port 8000' -R 'http.host and http.request.uri' -T fields -e http.host -e http.request.uri -l | tr -d 't'
说明:sql
须要从抓包的文件evidence04.pcap中提取出报文相关数据信息,如时间、源IP、目的IP、协议名、源Port、標Port、包大小等信息,最后输出到csv文件。shell
tshark -r evidence.pcap -T fields -e frame.time_relative -e ip.src -e ip.dst -e ip.proto -e tcp.srcport -e tcp.dstport -e frame.len -E header=n -E separator=, -E quote=n -E occurrence=f > output.csv
说明:json
使用tshark过滤dns cap包中源ip、目的ip、request请求segmentfault
tshark -r test.cap -T fields -e frame.time -e ip.src -e ip.dst -e dns.qry.name -R 'udp.dstport==53 || dns'
说明:网络
tshark -r 20190409.pcap -f 'udp' -w udp-20190409.pcap
读取文件时只能使用显示过滤,也就是只能使用-Y
或-2 -R
过滤tcp
tshark -r 20190409.pcap -R 'udp' -w udp-20190409.pcap
显示过滤-R
参数须要和-2
一块儿使用,或使用-Y
ide
参考:
系列文章: