通常使用 Wireshark 处理一个较大的捕获文件时,可能处理速度会很慢,或者甚至没响应。当捕获文件超过 100MB 时,使用显示过滤器、添加列或构建图表都可能很慢。为了快速地分析数据,这时候可以将该文件分割为文件集。下面我们介绍如何进行大文件分割。
一、使用 Capinfos 获取文件大小和包数
Capinfos 是一个命令行工具,它可以查看关于捕获文件的基本信息。 Capinfos 包括在 Wireshark 中,保存在 Wireshark 程序目录中。
Capinfos 工具的语法格式如下:
capinfos <filename>
如查看 http.pcapng 捕获文件的基本信息。执行命令如下:
capinfos http.pcapng
执行以上命令后,显示结果如下所示。
D:\Program Files (x86)\Wireshark>capinfos.exe e:\file\wireshark\http.pcapng
File name: e:\file\wireshark\http.pcapng
File type: Wireshark/... - pcapng
File encapsulation: Ethernet
File timestamp precision: microseconds (6)
Packet size limit: file hdr: (not set)
Number of packets: 19 k
File size: 11 MB
Data size: 10 MB
Capture duration: 383.494118 seconds
First packet time: 2016-03-01 16:45:54.769930
Last packet time: 2016-03-01 16:52:18.264048
Data byte rate: 27 kBps
Data bit rate: 223 kbps
Average packet size: 547.29 bytes
Average packet rate: 51 packets/s
SHA1: 5f93c9a4026705fe16f86f8f2a35d369176ec6cc
RIPEMD160: 3455e805691383afca21ee5209792461dfbfc643
MD5: eab737fefa1058850bb4b19fd5c694e7
Strict time order: True
Number of interfaces in file: 1
Interface #0 info:
Name = \Device\NPF_{3866F6C2-1EFA-4A37-A62B-AE28EF24ABBD}
Description = NONE
Encapsulation = Ethernet (1/1 - ether)
Speed = 0
Capture length = 262144
FCS length = -1
Time precision = microseconds (6)
Time ticks per second = 1000000
Time resolution = 0x06
Filter string = NONE
Operating system = 64-bit Windows 10, build 10240
Comment = NONE
BPF filter length = 0
Number of stat entries = 0
Number of packets = 19572
D:\Program Files (x86)\Wireshark>
从结果中可以看到 http.pcapng 捕获文件的基本信息,包括文件类型、封装、包大小限制、包数、文件大小及时间等。
二、分割文件
通过使用 Capinfos 命令查看包的基本信息,可以判断出那些文件较大。对于大的捕获文件,就可以使用 editcap 命令分割。具体步骤如下。
1、打开 windows DOS 命令窗口。
2、进入 editcap 程序所在目录。然后运行 editcap 命令,如下所示。
D:\Program Files (x86)\Wireshark>editcap.exe -c 1000 e:\file\Wireshark\http.pcapng e:\file\Wireshark\port.pcapng
以上命令表示将捕获文件 http.pcapng 分割成以 port*.pcapng 为名称的文件集,并且分割后每个文件的包数最大为1000.
3、查看生成的文件集。
D:\Program Files (x86)\Wireshark>dir e:\file\Wireshark\port*
驱动器 E 中的卷是 文档
卷的序列号是 000F-D904
e:\file\Wireshark 的目录
2016/03/01 18:16 373,140 port_00000_20160301164554.pcapng
2016/03/01 18:16 667,332 port_00001_20160301164602.pcapng
2016/03/01 18:16 746,920 port_00002_20160301164609.pcapng
2016/03/01 18:16 447,524 port_00003_20160301164616.pcapng
2016/03/01 18:16 504,856 port_00004_20160301164639.pcapng
2016/03/01 18:16 294,180 port_00005_20160301164710.pcapng
2016/03/01 18:16 525,172 port_00006_20160301164808.pcapng
2016/03/01 18:16 855,336 port_00007_20160301164845.pcapng
2016/03/01 18:16 776,880 port_00008_20160301164853.pcapng
2016/03/01 18:16 818,836 port_00009_20160301164902.pcapng
2016/03/01 18:16 519,440 port_00010_20160301164924.pcapng
2016/03/01 18:16 788,192 port_00011_20160301165015.pcapng
2016/03/01 18:16 820,724 port_00012_20160301165017.pcapng
2016/03/01 18:16 736,680 port_00013_20160301165018.pcapng
2016/03/01 18:16 898,108 port_00014_20160301165028.pcapng
2016/03/01 18:16 444,648 port_00015_20160301165030.pcapng
2016/03/01 18:16 279,312 port_00016_20160301165106.pcapng
2016/03/01 18:16 426,836 port_00017_20160301165134.pcapng
2016/03/01 18:16 304,352 port_00018_20160301165144.pcapng
2016/03/01 18:16 133,736 port_00019_20160301165202.pcapng
20 个文件 11,362,204 字节
0 个目录 13,524,697,088 可用字节
D:\Program Files (x86)\Wireshark>
以上输出的信息显示了将 http.pcapng 分割成的多个文件,这些文件就是一个文件集。
三、合并多个捕获文件
当用户想要查看所有数据时,通常需要将几个小文件合并起来。如构建所有数据的图表、使用显示过滤器查找关键字、启动分层协议对话框查看可疑的协议或应用程序等。
在 Wireshark 中,使用 Mergecap 程序将几个小文件合并成一个大文件。
1、打开终端。
2、切换到 Mergecap 程序所在的目录。查看前面创建的捕获文件集。
D:\Program Files (x86)\Wireshark>dir e:\file\Wireshark\port*
3、使用 mergecap 命令将每个小文件进行合并。
D:\Program Files (x86)\Wireshark>mergecap.exe -w e:\file\Wireshark\port.pcapng e:\file\Wireshark\port*
4、查看合并成的新文件。
D:\Program Files (x86)\Wireshark>dir e:\file\Wireshark\port.pcapng
驱动器 E 中的卷是 文档
卷的序列号是 000F-D904
e:\file\Wireshark 的目录
2016/03/01 18:46 11,360,108 port.pcapng
1 个文件 11,360,108 字节
0 个目录 13,513,334,784 可用字节