查看传入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 

正如你所看到的,这不是我正在寻找什么。

你调用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 [...] 

grepselect一些长度信息的行(几乎全部是这些行)和一些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 [...]