查看传入 IP 的数据包大小

查看传入 IP 的数据包大小

几个小时以来,我一直在寻找解决方案。无果后,我在这里寻求帮助。

我需要按大小查看传入的数据包。格式类似于:

IP SIZE

我尝试过 TCPDUMP,但它没有给出实际数据包的大小。这很糟糕。我知道这是可能的,但我不知道怎么做。

执行 tcpdump 命令时我得到以下信息:

root@lax:~# tcpdump -n -i eth1 -A -x dst port 443 and greater 10 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
01:11:22.474691 IP 187.187.66.133.161 > *.*.*.*.443:  GetResponse(464)  .1.3.6.1.2.1.1.1.0="Ubee PacketCable 1.5 W-EMTA <<HW_REV: 2.65.1; VENDOR: Ubee; BOOTR: 9.1.1b; SW_REV: 6.32.1007; MODEL: DVW222B.D>>" .1.3.6.1.2.1.1.2.0=.1.3.6.1.4.1.4413.2.1.6 .1.3.6.1.2.1.1.3.0=11673700 .1.3.6.1.2.1.1.4.0="(unknown)" .1.3.6.1.2.1.1.5.0="CableHome" .1.3.6.1.2.1.1.6.0="(unknown)" .1.3.6.1.2.1.1.7.0=3 .1.3.6.1.2.1.1.8.0=0 .1.3.6.1.2.1.1.9.1.2.1=.1.3.6.1.4.1.4413.2.3.2.4 .1.3.6.1.2.1.1.9.1.3.1="An agent which supports all MIBs required by the DOCSIS 2.0 OSS specification as well as those specified by the 2.0+IPv6 technical report."
    0x0000:  4500 01ff 0358 0000 3311 a2e7 bbbb 4285
    0x0010:  602c 8142 00a1 01bb 01eb 8562 3082 01df
    0x0020:  0201 0104 0670 7562 6c69 63a2 8201 d002
    0x0030:  024e 4702 0100 0201 0030 8201 c230 7c06
    0x0040:  082b 0601 0201 0101 0004 7055 6265 6520
    0x0050:  5061 636b 6574 4361 626c 6520 312e 3520
[...]
    0x01f0:  6368 6e69 6361 6c20 7265 706f 7274 2e

正如您所见,这根本不是我想要的。

答案1

您对 的调用使事情变得过于复杂tcpdump;也就是说,您花费精力打印了太多您不想要的信息。如果让它自行运行,则会tcpdump在大多数行的末尾打印长度信息;例如:

[root@risby ~]# tcpdump -n -n -i eth1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
09:44:10.134745 IP6 2a01:2c0:e:300:7271:bcff:feac:445a.50367 > 2a01:8000:0:4::1:1.993: Flags [P.], seq 2525222567:2525222611, ack 1131700467, win 1432, options [nop,nop,TS val 676470793 ecr 1793162882], length 44
09:44:10.163565 IP6 2a01:8000:0:4::1:1.993 > 2a01:2c0:e:300:7271:bcff:feac:445a.50367: Flags [P.], seq 1:59, ack 44, win 1174, options [nop,nop,TS val 1793315067 ecr 676470793], length 58
[...]

通过grep选择一些带有长度信息的行(几乎是全部行)并perl删除之前的大部分行,您可以快速而粗略地实现您想要的内容:

[root@risby ~]# tcpdump -n -n -i eth1 | grep --line-buffered 'length' | perl -n -e 's/.*length/length/; print $_'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
length 32
length 24
length 160
length 0
length 192
length 0
length 240
[...]

相关内容