tcpdump 的命令,提供几个特定大小的标准 txt 输出

Command of tcpdump that gives several standard txt output with specific size

我想要标准结构的 tcpdump 输出。如下所示:

05:49:56.604899 00:00:00:00:00:02 > 00:00:00:00:00:03, ethertype IPv4 (0x0800), length 10202: 10.0.0.2.54880 > 10.0.0.3.5001: Flags [.], seq 3641977583:3641987719, ack 129899328, win 58, options [nop,nop,TS val 432623 ecr 432619], length 10136
05:49:56.604908 00:00:00:00:00:03 > 00:00:00:00:00:02, ethertype IPv4 (0x0800), length 66: 10.0.0.3.5001 > 10.0.0.2.54880: Flags [.], ack 10136, win 153, options [nop,nop,TS val 432623 ecr 432623], length 0
05:49:56.604900 00:00:00:00:00:02 > 00:00:00:00:00:03, ethertype IPv4 (0x0800), length 4410: 10.0.0.2.54880 > 10.0.0.3.5001: Flags [P.], seq 10136:14480, ack 1, win 58, options [nop,nop,TS val 432623 ecr 432619], length 4344

然而,对我来说重要的是将所有这些结构化信息保存在 10 个大小为 10 MB 的文件中。我知道我必须使用这个命令:

tcpdump -i h1-eth0 -w /tmp/trace.txt -W 10 -C 10 -K -n

但问题是,输出不是标准方式。你能帮我找到一个命令,让我在 10 个大小为 10 MB 的文件中给出 tcpdump 的标准输出吗?

我可以使用一个技巧来做到这一点。我制作了一个简单的 bash 脚本来将 pcap 文件转换为 txt 文件。在 运行 我的 tcpdump 之后,我执行了脚本,它在我需要的一个周期内运行良好。如果您需要对所有循环都这样做,您可以将 for 循环替换为 while 循环。

#!/bin/bash

dir="tmp"
#tcpdump -i h1-eth0 -w /tmp/trace -W 10 -C 10 -K -n 

for f in `ls /tmp`; do
echo $f; 
echo /tmp/$f;
echo /media/sf_sharedsaeed/Test/$f.txt;
sudo tcpdump -r /tmp/$f >> /media/sf_sharedsaeed/Test/$f.txt
rm /tmp/$f
done