pcap文件格式

合集下载

Wireshark的Pcap文件格式分析及解析源码

Wireshark的Pcap文件格式分析及解析源码

Wireshark的Pcap文件格式分析及解析源码Wireshark的Pcap文件格式分析及解析源码下面主要介绍下Ethereal默认的*.pcap文件保存格式。

Pcap文件头24B各字段说明:Magic:4B:0x1A 2B 3C 4D:用来标示文件的开始Major:2B,0x02 00:当前文件主要的版本号Minor:2B,0x04 00当前文件次要的版本号ThisZone:4B当地的标准时间;全零SigFigs:4B时间戳的精度;全零SnapLen:4B最大的存储长度LinkType:4B链路类型常用类型:0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 "raw IP", with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux "cooked" capture114 LocalTalkPacket 包头和Packet数据组成字段说明:Timestamp:时间戳高位,精确到secondsTimestamp:时间戳低位,精确到microsecondsCaplen:当前数据区的长度,即抓取到的数据帧长度,由此可以得到下一个数据帧的位置。

Len:离线数据长度:网络中实际数据帧的长度,一般不大于caplen,多数情况下和Caplen数值相等。

pcap使用手册

pcap使用手册

pcap使用手册让我们从看看这篇文章写给谁开始。

显而易见的,需要一些C语言基础知识,除非你只想了解基本的理论。

你不必是一个编码专家,因为这个领域只有经验丰富的程序员涉足,而我将尽可能详细的描述这些概念。

另外,考虑到这是有关一个包嗅探器的,所以对网络基础知识的理解是有帮助的。

所有在此出现的代码示例都已在FreeBSD 4.3平台上测试通过。

开始:pcap应用程序的格式我们所要理解的第一件事情是一个基于pcap的嗅探器程序的总体布局。

流程如下:1.我们从决定用哪一个接口进行嗅探开始。

在Linux中,这可能是eth0,而在BSD系统中则可能是xl1等等。

我们也可以用一个字符串来定义这个设备,或者采用pcap提供的接口名来工作。

2.初始化pcap。

在这里我们要告诉pcap对什么设备进行嗅探。

假如愿意的话,我们还可以嗅探多个设备。

怎样区分它们呢?使用文件句柄。

就像打开一个文件进行读写一样,必须命名我们的嗅探“会话”,以此使它们各自区别开来。

3.如果我们只想嗅探特定的传输(如TCP/IP包,发往端口23的包等等),我们必须创建一个规则集合,编译并且使用它。

这个过程分为三个相互紧密关联的阶段。

规则集合被置于一个字符串内,并且被转换成能被pcap读的格式(因此编译它)。

编译实际上就是在我们的程序里调用一个不被外部程序使用的函数。

接下来我们要告诉pcap使用它来过滤出我们想要的那一个会话。

4.最后,我们告诉pcap进入它的主体执行循环。

在这个阶段内pcap一直工作到它接收了所有我们想要的包为止。

每当它收到一个包就调用另一个已经定义好的函数,这个函数可以做我们想要的任何工作,它可以剖析所部获的包并给用户打印出结果,它可以将结果保存为一个文件,或者什么也不作。

5.在嗅探到所需的数据后,我们要关闭会话并结束。

这是实际上一个很简单的过程。

一共五个步骤,其中一个(第3个)是可选的。

我们为什么不看一看是怎样实现每一个步骤呢?设置设备这是很简单的。

wireshark 抓包的格式

wireshark 抓包的格式

Wireshark是一种流行的网络分析工具,它可以捕获和分析网络数据包。

Wireshark抓包的格式是非常重要的,它决定了我们如何解析和分析捕获到的数据包。

本文将介绍Wireshark抓包的格式,包括常见的文件类型和数据结构,并探讨如何有效地利用这些格式进行网络分析和故障排查。

一、Wireshark抓包的文件格式Wireshark可以将捕获到的数据包保存为不同的文件格式,其中常见的包括pcap、pcapng、cap、etl等。

不同的文件格式具有不同的特点和用途,下面我们将逐一介绍它们。

1. pcap格式pcap(Packet Capture)是Wireshark最常用的文件格式,它可以保存捕获到的网络数据包以及相关的信息,如时间戳、数据长度、数据内容等。

pcap格式的文件通常使用libpcap或WinPcap库进行读取和分析,它可以跨评台使用,并且被许多网络工具和应用程序所支持。

2. pcapng格式pcapng(Packet Capture Next Generation)是Wireshark的一种新文件格式,它在pcap的基础上进行了扩展和改进,支持更多的元数据和信息字段。

pcapng格式的文件通常包含多个数据块(Block),每个数据块都可以保存不同类型的数据,如捕获配置信息、数据包数据、接口信息等。

pcapng格式的文件在Wireshark 1.8及以上版本中得到支持,在一些特定场景下具有更好的灵活性和可扩展性。

3. cap格式cap格式是一种比较老旧的文件格式,它通常用于微软网络监控工具或特定的硬件设备。

cap格式的文件结构较为简单,通常包含数据包的原始内容和一些简单的元数据信息,不支持一些高级的特性和功能。

4. etl格式etl(Event Trace Log)格式是一种Windows事件跟踪日志文件格式,它通常用于收集系统和应用程序的事件信息。

在一些特定情况下,我们也可以使用Wireshark来解析和分析etl格式的数据包,不过需要借助一些额外的工具和插件。

netflow pcap解析

netflow pcap解析

netflow pcap解析
PCAP(Packet CAPture)是一种用于捕获和存储网络数据包的文件格式。

它通常用于网络分析、故障排除和安全审计等领域。

要解析 NetFlow PCAP 文件,你可以使用专门的网络分析工具或库,这些工具和库可以读取 PCAP 文件并提取其中的 NetFlow 数据。

一些常用的工具和库包括:
1. Wireshark:一款流行的网络协议分析器,它可以读取 PCAP 文件并提供可视化的界面来分析数据包。

2. tcpdump:一个命令行工具,用于捕获和分析网络数据包,可以将其输出保存为 PCAP 文件。

3. libpcap:一个用于处理 PCAP 文件的库,它提供了 API 来读取、解析和处理 PCAP 文件。

解析 NetFlow PCAP 文件的一般步骤包括:
1. 读取 PCAP 文件:使用适当的工具或库,读取 PCAP 文件并加载其中的数据包。

2. 提取 NetFlow 数据:根据 PCAP 文件中记录的数据包,提取出 NetFlow 数据。

NetFlow 数据通常包括源 IP 地址、目标 IP 地址、端口号、协议类型、流量统计等信息。

3. 分析和处理 NetFlow 数据:根据提取的 NetFlow 数据,进行进一步的分析和处理,例如计算流量统计、识别异常流量、绘制网络拓扑等。

请注意,解析 NetFlow PCAP 文件可能需要一定的网络分析知识和技能。

如果你对网络分析不熟悉,建议先学习相关的基础知识和工具使用方法。

此外,具体的解析步骤和方法可能因使用的工具和库而有所不同,请根据你使用的具体工具和库的文档进行参考。

pcap及pcapng格式解析中文版

pcap及pcapng格式解析中文版

PCAP下一代转储文件格式PCAP-DumpFileFormatStatus of this MemoThis document is an Internet-Draft and is in full conformance with all provisions of Section 10 of RFC 2026.Internet-Drafts are working documents of the InternetEngineering Task Force (IETF), its areas, and its workinggroups. Note that other groups may also distribute working documents as Internet-Drafts.Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to useInternet-Drafts as reference material or to cite them other than as “work in progress.”The list of current Internet-Drafts can be accessedat /ietf/1id-abstracts.txt.The list of Internet-Draft Shadow Directories can be accessed at /shadow.html.This Internet-Draft will expire on September 2, 2004. Copyright NoticeCopyright © The Internet Society (2004). All RightsReserved.AbstractThis document describes a format to dump captured packets on a file. This format is extensible and it is currently proposed for implementation in the libpcap/WinPcap packet capturelibrary.Updates∙[27 Jul 2009] Guy Harris: added some missing reserved block types in Appendix B.∙[27 Jul 2009] Guy Harris: fixed a typo in Appendix B.The range of standardized blocks are in the range0x00000000-0x7FFFFFFF.∙[ 8 Feb 2008] Gianluca Varenni: better documentation for the format of the timestamps. Renamed theif_tsaccur option into if_tsresol.∙[22 Oct 2007] Gianluca Varenni: added a note related to 64-bit alignment. Specified that the option lengthfield is the length without padding. typos here and there.Added some option examples.∙[17 Oct 2007] Ulf Lamping: Major review: "Interface ID" in "ISB" now 32 bits. isb_starttime/isb_endtimedepends on if_tsaccur. Lot's of other editing ...∙[ 8 Oct 2007] Ulf Lamping: Fixed several typos.Grouped the block types into mandatory, optional,experimental, obsolete.∙[14 Sep 2006] Gianluca Varenni: Added the block type code for Arinc 429 in AFDX Encapsulation InformationBlock∙[23 May 2006] Gianluca Varenni: Added the block type code for IRIG Timestamp Block∙[23 Apr 2006] Gianluca Varenni: Cleaned up AppendixC a bit: we should use the LINKTYPE_xxx values fromlibpcap, not the DLT_xxx ones. Fixed the introduction tothe appendix and added some comments.∙[21 Mar 2006] Gianluca Varenni: Added a preliminary version of Appendix C, detailing the Standardized LinkTypes.∙[21 Mar 2006] Gianluca Varenni: Added a preliminary version of Appendix B, detailing the Standardized BlockType codes.∙[21 Mar 2006] Gianluca Varenni: Added the Enhanced Packet Block in section 2.2. Fixed a typo in the list: it'sInterface Statistics Block, and not Capture StatisticsBlock.∙[21 Mar 2006] Gianluca Varenni: Fixed some minor typos in the document.∙[21 Mar 2006] Gianluca Varenni: Fixed an error inPacket Block: option pack_hash should have code 3.∙[21 Mar 2006] Gianluca Varenni: Added the definition of the Enhanced Packet Block.∙[12 Mar 2006] Gianluca Varenni: Added optionif_tsoffset in the Interface Description Block.目录PCAP下一代转储文件格式 (1)PCAP-DumpFileFormat (1)Status of this Memo (1)Copyright Notice (1)Abstract (2)Updates (2)1. 目标 (5)2. 文件结构(General File Structure) (5)2.1. 块结构(General Block Structure) (5)2.2. 块类型(Block Types) (6)2.3. 逻辑块层次结构(Logical Block Hierarchy) (7)2.4. 物理文件的布局(Physical File Layout) (7)2.5. 选项(Options) (9)2.6. 数据格式(Data format) (10)3. 块定义(Block Definition) (11)3.1. 节头块(Section Header Block) (11)3.2. 接口描述块(Interface Description Block) (12)3.3. 增强分组块(Enhanced Packet Block) (15)3.4. 简单分组块(Simple Packet Block) (17)3.5. 分组块(Packet Block) (18)3.6. 名称解析块(Name Resolution Block) (20)3.7. 接口统计块(Interface Statistics Block) (22)4. 实验块(Experimental Blocks) (23)4.1. 替代性分组块(Alternative Packet Blocks) (23)4.2. 压缩块(Compression Block) (24)4.3. 加密块(Encryption Block) (24)4.4. 固定长度块(Fixed Length Block) (25)4.5. 目录块(Directory Block) (26)4.6. 流量统计和监控块(Traffic Statistics and Monitoring Blocks) (26)4.7.事件/安全块(Event/Security Block) (26)5. 推荐的扩展名: .pcapng (27)6. 怎样增加供应商/域特定扩展 (27)7. 结论 (27)Appendix A. Packet Block Flags Word (28)Appendix B. Standardized Block Type Codes (28)Appendix C. Standardized Link Type Codes (29)Appendix D. Link Layer Headers (33)Authors' Addresses (34)Full Copyright Statement (34)Intellectual Property (35)Acknowledgment (35)附录:pcap文件格式说明 (36)文件格式 (36)ile Header (36)Record (Packet) Header (37)Packet Data (38)1. 目标交换分组痕迹的问题变得越来越关键。

PCAP包结构

PCAP包结构
}
说明:
1、时间戳,包括:
秒计时:32位,一个UNIX格式的精确到秒时间值,用来记录数据包抓获的时间,记录方式是记录从格林尼治时间的1970年1月1日00:00:00到抓包时经过的秒数;
毫秒计时:32位,抓取数据包时的毫秒值。
a time stamp, consisting of:
a UNIX-format time-in-seconds when the packet was captured, i.e. the number of seconds since January 1,1970, 00:00:00 GMT (that GMT, *NOT* local time!);
a 32-bit time stamp accuracy field tha not actually used,so you can (and probably should) just make it 0;
6、数据包最大长度:32位,该值设置所抓获的数据包的最大长度,如果所有数据包都要抓获,将该值设置为65535;例如:想获取数据包的前64字节,可将该值设置为64。
the number of microseconds since that second when the packet was captured;
2、数据包长度:32位,标识所抓获的数据包保存在pcap文件中的实际长度,以字节为单位。
a 32-bit value giving the number of bytes of packet data that were captured;
3、数据包实际长度:所抓获的数据包的真实长度,如果文件中保存不是完整的数据包,那么这个值可能要比前面的数据包长度的值大。

pcap文件格式和wireshark解析

pcap文件格式和wireshark解析

pcap文件格式和wireshark解析pcap文件头pcap文件头参见官方说明用python代码表达结构如下,I是32位无符号数,下面的定义均采用32位方式# bpf_u_int32 magic; 固定为0xA1B2C3D4,表示pcap包文件# u_short version_major; 主版本号# u_short version_minor; 分支版本号# bpf_int32 thiszone; 时区# bpf_u_int32 sigfigs;# bpf_u_int32 snaplen; 每个包的最大长度# bpf_u_int32 linktype; 链路层协议族self.struct_pcap_file_header = '!I2H4I'pcap每个包的头参见# struct timeval ts;# bpf_u_int32 caplen;# bpf_u_int32 len;self.struct_pcap_pkthdr = '!4I'timeval是c的时间戳结构体,前面一个整型数是秒数偏置,后面一个整型数是微秒偏置,详情可以查阅相关文档生成pcap文件使用python简单生成,写入到test.pcap文件,写入了两个包到该文件,linktype设置为162,在wireshark源码中表示保留给用户的USER15 类型# -*-coding:utf-8-*-"""Author:yinshunyaoDate:2017/3/24 0024上午 10:47"""import unittestimport structclass PacpTest(unittest.TestCase):def setUp(self):# pcap文件头格式## bpf_u_int32 magic; 固定为0xA1B2C3D4,表示pcap包文件# u_short version_major; 主版本号# u_short version_minor; 分支版本号# bpf_int32 thiszone; 时区# bpf_u_int32 sigfigs;# bpf_u_int32 snaplen; 每个包的最大长度# bpf_u_int32 linktype; 链路层协议族self.struct_pcap_file_header = '!I2H4I'# pcap包头格式## struct timeval ts;# bpf_u_int32 caplen;# bpf_u_int32 len;self.struct_pcap_pkthdr = '!4I'# 文件头self.file_header = struct.pack(self.struct_pcap_file_header,0xA1B2C3D4, 4, 1, 0, 0, 0xFFFF, 162 # USER15)def test_generate_pcap(self):# 消息体内容pkg_content1 = struct.pack('!2I', 100,101)pkg_content2 = struct.pack('!2I', 101,100)#pkg_header = struct.pack(self.struct_pcap_pkthdr, 0x4A5B1784,0x00081C6D,len(pkg_content1), len(pkg_content1))with open('test.pcap', 'wb') as test:test.write(self.file_header+pkg_header+pkg_content1+pkg_header+pkg_content2)wireshark解析效果用自定义的wireshark插件协议解析整体效果如下,后面具体介绍插件内容,可以看到Encapsulation type字段值是60,协议是USER15这个值跟前面文件头里面的link162的映射关系,在wireshark中完成,具体处理可以查看wireshark的C源码。

wireshark 格式解析

wireshark 格式解析

wireshark 格式解析摘要:1.引言2.Wireshark 简介3.Wireshark 的文件格式4.Wireshark 文件格式的解析5.总结正文:Wireshark 是一款流行的网络协议分析器,它可以用于捕获、查看和分析网络数据包。

Wireshark 支持多种文件格式,包括PCAP、PCAP-NG、JSON 等。

本文将介绍Wireshark 的文件格式及其解析方法。

Wireshark(以前称为Ethereal)是一款功能强大的网络协议分析器,广泛应用于网络故障排除、网络安全分析和网络优化等领域。

Wireshark 支持多种文件格式,其中最常用的是PCAP 格式。

PCAP(Packet Capture)是一种通用的网络数据包捕获格式,它可以存储网络数据包的原始内容,便于后续分析。

除了PCAP 格式,Wireshark 还支持其他文件格式,如PCAP-NG、JSON 等。

要解析Wireshark 文件,首先需要了解其文件格式。

Wireshark 的文件格式主要包括以下几部分:1.文件头(File Header):文件头包含文件的基本信息,如文件版本、数据包计数、时间戳等。

2.数据包列表(Packet List):数据包列表包含文件中所有的数据包。

每个数据包包含以下信息:- 数据包序号(Packet Number)- 时间戳(Timestamp)- 数据包长度(Packet Length)- 数据包内容(Packet Contents)Wireshark 文件格式的解析主要依赖于Wireshark 本身。

使用Wireshark 打开一个文件,可以直观地查看文件中的数据包列表,以及每个数据包的详细信息。

此外,Wireshark 还提供了丰富的过滤和搜索功能,可以帮助用户快速定位感兴趣的数据包。

总之,Wireshark 是一款功能强大的网络协议分析器,支持多种文件格式。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

PCAP文件格式每个.pcap文件的文件头Pcap Header:24B每个.pcap文件中的数据包头 Packet Header:16B每个.pcap文件中的数据报 Packet Data:14B以太头+TCP/IP数据具体如下:1.pcap文件头部(pcap header)sturct pcap_file_header{DWORD magic;WORD version_major;WORD version_minor;DWORD thiszone;DWORD sigfigs;DWORD snaplen;DWORD linktype;}说明:1、标识位magic:32位的,这个标识位的值是16进制的 0xa1b2c3d4。

32-bit magic number , The magic number has the value hex a1b2c3d4.2、主版本号version_major:16位,默认值为0x2。

返回写入被打开文件所使用的pcap函数的主版本号。

16-bit major version number, The major version number should have the value 2.3、副版本号version_minor:16位,默认值为0x04。

16-bit minor version number, The minor version number should have the value 4.4、区域时间thiszone:32位,实际上该值并未使用,因此可以将该位设置为0。

32-bit time zone offset field that actually not used, so you can (and probably should) just make it 0;5、精确时间戳sigfigs:32位,实际上该值并未使用,因此可以将该值设置为0。

32-bit time stamp accuracy field that not actually used, so you can (and probably should) just make it 0;6、数据包最大长度snaplen:32位,该值设置所抓获的数据包的最大长度,如果所有数据包都要抓获,将该值设置为65535;例如:想获取数据包的前64字节,可将该值设置为64。

32-bit snapshot length" field; The snapshot length field should be the maximum number of bytes perpacket that will be captured. If the entire packet is captured, make it 65535; if you only capture, for example, the first 64 bytes of the packet, make it 64.7、链路层类型linktype:32位,数据包的链路层包头决定了链路层的类型。

32-bit link layer type field. The link-layer type depends on the type of link-layer header that the packets in the capture file have:以下是数据值与链路层类型的对应表0 BSD loopback devices, except for later OpenBSD1 Ethernet, and Linux loopback devices 以太网类型,大多数的数据包为这种类型。

6 802.5 Token Ring7 ARCnet8 SLIP9 PPP10 FDDI100 LLC/SNAP-encapsulated ATM101 raw IP, with no link102 BSD/OS SLIP103 BSD/OS PPP104 Cisco HDLC105 802.11108 later OpenBSD loopback devices (with the AF_value in network byte order)113 special Linux cooked capture114 LocalTalk文件头部后面就是一个一个的数据包头部与数据内容了,格式如下:2. 数据包头结构struct pcap_pkthdr{struct timeval ts; /* time stamp */bpf_u_int32 caplen; /* length of portion present */bpf_u_int32 len; /* length this packet (off wire) */};ts:时间戳cpalen:当前分组的长度len:数据包的长度struct timeval结构体在time.h中的定义为:struct timeval{__time_t tv_sec; /* Seconds. */__suseconds_t tv_usec; /* Microseconds. */};其中,tv_sec为Epoch到创建struct timeval时的秒数,tv_usec为微秒数,即秒后面的零头。

说明:(1) DWORD就是32bit的unsigned long。

(2) 时间戳,包括:秒计时:32位,一个UNIX格式的精确到秒时间值,用来记录数据包抓获的时间,记录方式是记录从格林尼治时间的1970年1月1日 00:00:00 到抓包时经过的秒数;毫秒计时:32位,抓取数据包时的毫秒值。

time stamp, consisting of: UNIX-format time-in-seconds when the packet was captured, i.e. the number of seconds since January 1,1970, 00:00:00 GMT (that GMT, *NOT* local time!);the number of microseconds since that second when the packet was captured;(3) 数据包长度:32位,标识所抓获的数据包保存在pcap文件中的实际长度,以字节为单位。

32-bit value giving the number of bytes of packet data that were captured;(4) 数据包实际长度:所抓获的数据包的真实长度,如果文件中保存不是完整的数据包,那么这个值可能要比前面的数据包长度的值大。

32-bit value giving the actual length of the packet, in bytes (which may be greater than the previous number, if you are not saving the entire packet).3. 数据包内容通常就是链路层的数据帧,长度就是Caplen,这个长度的后面,就是当前PCAP文件中存放的下一个Packet数据包,也就是说:PCAP文件里面并没有规定捕获的Packet数据包之间有什么间隔字符串,下一组数据在文件中的起始位置。

我们需要靠第一个Packet包确定。

最后,Packet数据部分的格式其实就是标准的网路协议格式了可以任何网络教材上找得到。

每个数据包的前14字节是以太头,后面才是ip首部等内容。

读取pcap文件有了pcap文件的格式说明之后,要读取pcap类型的文件就很简单了。

这里只是分离出pcap文件里面一个一个的数据包,而没有对每个数据包进行单独的解析。

打开一个pcap文件,解析后将其写入一个文本文件:fopen = open('f:\\test.pcap','rb')fwrite = open('f:\\result.txt','w')stringPacket = fopen.read()这样整个pcap文件的内容就已经存储在stringPacket里面了,可见该程序在处理大型的pcap文件时候并不适合。

首先找到该pcap文件的头部极其描述,并将其一个一个的写入txt:pcapHeader = {}pcapHeader['magic'] = stringPacket[0:4]pcapHeader['version_major'] = stringPacket[4:6]pcapHeader['version_minor'] = stringPacket[6:8]pcapHeader['thiszone'] = stringPacket[8:12]pcapHeader['sigfigs'] = stringPacket[12:16]pcapHeader['snaplen'] = stringPacket[16:20]pcapHeader['linktype'] = stringPacket[20:24]fwrite.write("the head of this pacpFile is:\n")for key in ['magic','version_major','version_minor','thiszone','sigfigs','snaplen','linktype']:fwrite.write(key + ":" + repr(pcapHeader[key]) + '\n')头部的各个字段,根据其位置,就可以一个一个的找出来了。

这里要说明一点的是,在写入文件的时候,如果用str()函数代替repr()函数,那么写入的全部是乱码。

这两个函数都是将参数转换为字符串类型,但是区别我还不知道,留待以后补充。

找出头部后,剩下的就是一个一个的数据包了。

这个时候,stringPacket已经指向第24个字节处了,令i=24,然后定义三个数据 pcap_pkthdr = {}存储每个数据包的头部, pcapData =''存储每个数据包的内容, pcapNum 记录是第几个数据包,初始化为1,接下来的代码如下:while i < len(stringPacket):pcap_pkthdr['GMTime'] = stringPacket[i:i+4]pcap_pkthdr['microTime'] = stringPacket[i+4:i+8]pcap_pkthdr['caplen'] = stringPacket[i+8:i+12]pcap_pkthdr['len'] = stringPacket[i+12:i+16]pcap_len = struct.unpack('I',pcap_pkthdr['len'])[0]print pcap_pkthdr['len']fwrite.write("the " + repr(pcapNum) + "th packet:\n")for key in ['GMTime','microTime','caplen','len']:fwrite.write(key + ":" + repr(pcap_pkthdr[key]) + '\n')fwrite.write("data: " + repr(stringPacket[i+16:i+16+int(pcap_len)]) + "\n")i = i + 16 + pcap_lenpcapNum = pcapNum + 1这样所有的数据包都被解析出来了。

相关文档
最新文档