本文由Balakrishnan M撰写
不久前,我们回顾了11个有关如何使用的示例 editcap实用程序 捕获网络转储。在本文中,让我们回顾一下mergecap实用程序和tshark命令。
Mergecap是一个数据包转储合并工具,它将多个转储合并到一个转储文件中。根据时间戳,数据包将按顺序写入输出文件。默认情况下,输出文件以libpcap格式编写。但是,使用mergecap选项,我们可以生成各种不同格式的输出,包括wireshark工具支持的格式。
Wireshark软件包中提供了mergecap。确保 Wireshk / ethereal包装 已安装以使用mergecap。
将两个转储文件合并为一个output_dump文件
合并input_dump1和input_dump2捕获文件并将其写入output_dump文件。
# mergecap -v input_dump1 input_dump2 -w output_dump
在此示例中,input_dump2包含在input_dump1之后捕获的数据包。 output_dump的开头将包含intput_dump2数据包,然后是intput_dump1数据包。
# mergecap input_dump1 input_dump2 -w output_dump -a
将输出转储文件打印到标准输出
合并两个网络转储文件,然后将输出打印到标准输出,而不是写入文件。
# mergecap -v input1_dump input2_dump -w -
以特定的封装格式打印输出文件
使用选项-T,以所需的封装格式获取输出文件,如下所示。
# mergecap -v -T ether -w merge_cap capture1 capture2 capture3
3.合并一定长度的数据包
在此示例中,output_dump包含最大100个字节长度的数据包。
# mergecap -v -s 100 dump1 dump2 dump3 -w output_dump
Tshark –数据包捕获工具
Tshark是捕获网络数据包的强大工具,可用于分析网络流量。它带有wireshark网络分析仪发行版。
连续捕获网络捕获
以下示例将连续60秒钟捕获网络数据包。捕获60秒后,它将自动停止。 capture_out包含在最近60秒内在网络中传输的数据包。
# tshark -q -w capture_out -a duration:60
在以下示例中,数据包将打印在屏幕上,同时将其写入输出文件。
# tshark -S -q -w capture_out -a duration:10
使用tshark捕获网络统计信息
要查看特定时间间隔内网络中有多少数据包流,请使用以下命令。
# tshark -q -w capture_duration1 -a duration:1 -z io,stat,1
捕获特定主机的网络数据包
使用以下示例,捕获特定主机(发送和接收的数据包)的数据包流。在此示例中,我们可以看到主机192.168.1.185每秒在网络中传输了多少个数据包
# tshark -S -q -w capture_duration6 -a duration:6 -z io,stat,1,ip.addr==192.168.1.150 After capturing all the packets for 6 seconds duration, it will print the statistics as like the following, 145 packets dropped 19749 packets captured IO Statistics Interval: 1.000 secs Column #0: ip.addr==192.168.1.185 | Column #0 Time |frames| 通过tes 000.000-001.000 2733 545242 001.000-002.000 2991 583374 002.000-003.000 3310 650716 003.000-004.000 3236 641896 004.000-005.000 3518 690860 005.000-006.000 3310 654988 006.000-007.000 638 122812
捕获特定端口上的网络数据包
本示例仅捕获ssh数据包。
# tshark -f “tcp port 22” -w capture_out
捕获特定时间段的网络数据包
以下示例将捕获特定持续时间(5秒)的数据包,并在捕获文件大小达到一定大小(1000KB)时切换到下一个文件。
# tshark -a filesize:1000 -a duration:5 -a files:5 -w ethcap1
样本输出捕获文件名的大小:
ethcap1_00001_20090216174203 - 1000K ethcap1_00002_20090216174205 - 1000K ethcap1_00003_20090216174207 - 835K
其他tshark捕获命令
使用选项-c,捕获直到某些数据包计数的数据包。以下示例仅用10个数据包创建ethcap1文件。
# tshark -c 10 -w ethcap1
使用选项-r从压缩文件中读取网络数据包。
# tshark -r capture_dump.gz
使用选项-r,仅显示特定的数据包类型。下面的示例仅在网络分析器中使用rtp数据包创建文件capture_dump。
# tshark -R “rtp” -r capture_dump
使用下面的过滤器捕获在端口1720中流动的tcp数据包。
# tshark -f “tcp port 1720”
以下示例将捕获到达端口1720或1721的数据包。
# tshark -f “port 1720 or port 1721” -w capture_dump
默认情况下,tshark将使用eth0设备进行数据包捕获。您还可以使用选项-i指定特定的以太网适配器,如下所示。
# tshark -i eth1 -w -a duration:10 capture_dump
本文作者: Balakrishnan Mariyappan。 他在工作 bk Systems(p)Ltd,并有兴趣为开源做贡献。 极客的东西welcomes your tips and 客座文章.
如果您喜欢这篇文章,您可能还会喜欢..
![]() |
![]() |
![]() |
![]() |