linux tcpdump的交叉编译以及使用

发布于:2024-04-29 ⋅ 阅读:(32) ⋅ 点赞:(0)

一、源码下载

官网:点击跳转

二、编译

1、解压

tar -xf libpcap-1.10.4.tar.xz

tar -xf tcpdump-4.99.4.tar.xz

2、配置及编译

//libpcap:
./configure --host=arm-linux --target=arm-linux CC=arm-linux-gcc --with-pcap=linux --prefix=$PWD/build

//tcpdump
./configure --host=arm-linux --target=arm-linux CC=arm-linux-gcc --prefix=$PWD/build

make && make install

三、命令使用

//监视指定网络接口eth0的数据包。若不指定网卡,默认tcpdump只会监视第一个网络接口,一般是eth0
tcpdump -i eth0 

//捕获以太网接口eth0上的数据包,并将它们写入到名为eth0.pcap的文件中
./tcpdump -i eth0 -w eth0.pcap 


//抓取eth0接口,122.224.241.154收发的包
tcpdump -i eth0 host 122.224.241.154 


//抓取30.30.30.30和40.40.40.40收发的包
tcpdump -i eth0 host 30.30.30.30 and 40.40.40.40 

//监视所有30.30.30.3发出的数据包
tcpdump -i eth0 src host 30.30.30.3 

//抓取122.224.241.154发送和接收的80端口的10个包
tcpdump -i eth0 host 122.224.241.154 and tcp port 80 -c 10 

//抓取网络地址是10.109.130.0/24的发送和接收的数据包
tcpdump -i eth0 net 10.109.130.0/24

//抓取192.168.102.156的ping包10个
tcpdump –i eth0 host 192.168.102.156 and icmp –c 10 

//抓取发送到192.168.107.216的ESP数据包
tcpdump -i eth0 dst host 192.168.107.216 and esp -nn 

//抓取发送到主机hao123或者百度的80端口的包
tcpdump -i eth0 port 80 and host www.hao123.com or www.baidu.com 

//抓取主机192.168.107.216发送或者接收的ICMP数据包详细信息,数量是20个,并保存到root下,文件名是1.cap
tcpdump -i eth0 host 192.168.107.216 -s 0 -c 20 –nnv -w /root/1.cap

//读取1.cap包内容
tcpdump -r /root/1.cap 



觉得有帮助的话,打赏一下呗。。