tcpdump使用

常用参数

选项类
选项 示例 说明
-i tcpdump -i eth0 指定网络接口,默认是0号接口(如eth0),any表示所有接口
-nn tcpdump -nn 不解析IP地址和端口号名称
-c tcpdump -c 5 限制要抓取的网络包的个数
-w tcpdump -w file.pcap 保存到文件中,一般用.pcap为后缀
过滤表达类
选项 示例 说明
host、src host、dst host tcpdump -nn host 192.168.1.1 主机过滤
port、src port、dst port tcpdump -nn port 80 端口过滤
ip、ip6、arp、tcp、udp、icmp tcpdump -nn tcp 协议过滤
and、or、not tcpdump -nn host 192.168.1.1 and port 80 逻辑表达式
tcp[tcoflages] tcpdump -nn "tcp[tcpflags] & tcp-syn != 0" 特定状态的TCP包

示例

抓取ping 百度的包

# ping www.baidu.com
tcpdump -i eth0 icmp and host www.baidu.com -w ping.pcap

抓取curl百度的包

# curl http://www.baidu.com
tcpdump -i eth0 tcp and host www.baidu.com and port 80 -w http.pcap
posted @ 2025-05-07 22:48  夜尽天明bylaw  阅读(9)  评论(0)    收藏  举报