tcpdump实例

1.tcpdump -D 获取网络适配器列表

linux:~ # tcpdump –D

 

1.eth0

2.br0

3.any (Pseudo-device that captures on all interfaces)

4.lo

 

2. tcpdump -i <需要监控的网络适配器编号/名称>

当我们不加任何选项执行tcpdump时,tcpdump将抓取通过所有网口的包;使用-i选项,我们可以在某个指定的网口抓包:

 

linux:~ # tcpdump -i eth0

 

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

19:56:11.936986 IP 192.168.0.148.sitaradir > linux.site.telnet: . ack 3650267677 win 16241

 

3.抓取指定数目的包(-c选项)

默认情况下tcpdump将一直抓包,直到按下”ctrl+c”中止,使用-c选项我们可以指定抓包的数量

 

linux:~ # tcpdump -c 1

 

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

19:57:45.442444 IP 192.168.0.148.sitaradir > linux.site.telnet: . ack 3650271151 win 15950

1 packets captured

4 packets received by filter

0 packets dropped by kernel

 

4. 抓取特定目标ip和端口的包

linux:~ # tcpdump host 192.9.200.59 and tcp port 8000

 

5. 如果想要显示数据包的内容,需要使用-X参数

linux:~ # tcpdump -i eth0 –X

 

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

20:05:13.368589 IP 192.168.0.148.sitaradir > linux.site.telnet: . ack 3650272030 win 15071

        0x0000:  4500 0028 c239 4000 7d06 1281 0a72 0994  E..(.9@.}....r..

        0x0010:  0a72 0a9e 0a47 0017 0f63 294c d992 bb1e  .r...G...c)L....

        0x0020:  5010 3adf 7421 0000 0000 0000 0000       P.:.t!........

 

6.捕获的数据太多,不断刷屏,可能需要将数据内容记录到文件里,需要使用-w参数:

linux:~ #tcpdump -X -s 0 -w test.cap host 192.9.200.59 and tcp port 8000

则将之前显示在屏幕中的内容,写入tcpdump可执行文件同级目录下的test.cap文件中。

 

文件查看方式如下,需要使用-r参数:

linux:~ #tcpdump -X -s 0 -r test.cap host 192.9.200.59 and tcp port 8000

 

如果这样写:

linux:~ #tcpdump -r test.cap

则只能看到最简单的数据传输交互过程,看不到数据包内容,查看时也需要使用相应的参数。

 

 

7.增加抓包时间戳(-tttt选项)

使用-tttt选项,抓包结果中将包含抓包日期:

linux:~ # tcpdump -tttt -i eth0

 

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

2013-10-24 20:09:01.064206 IP 192.168.0.148.sitaradir > linux.site.telnet: . ack 3650285440 win 15823

2013-10-24 20:09:01.064221 IP linux.site.telnet > 192.168.0.148.sitaradir: P 1:148(147) ack 0 win 5840

2013-10-24 20:09:01.064482 IP linux.site.47588 > dns1.zte.com.cn.domain: 4185+ PTR? 148.9.114.10.in-addr.arpa. (43)

 

8.抓取特定目标ip和端口的包

linux:~ # tcpdump -tttt -i eth0 -s 0 -w test.cap host 192.168.0.148 and tcp port 23

 

注:-s 0 表示不限制包长度,全部写入。

猜你喜欢

转载自dbajun.iteye.com/blog/1964203