Pkg.PCAP
— API for parsing PCAP and PCAPNG packet capture files¶
Parsing a PCAP File¶
The following code example demonstrates how to parse a PCAP file:
from Pro.Core import *
from Pkg.PCAP import *
def parsePCAP(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = PCAPObject()
if not obj.Load(c) or not obj.Parse():
return
for packet in obj.IteratePackets():
out = NTTextBuffer()
packet.Dump(out)
print(out.buffer)
Module API¶
Pkg.PCAP module API.
Classes:
This class represents a PCAP or PCAPNG capture file.
This class represents a single packet.
- class PCAPObject¶
Bases:
Pro.Core.CFFObject
This class represents a PCAP or PCAPNG capture file.
Methods:
Iterates through the packets.
Parse
()Parses the format.
- IteratePackets() → Optional[Pkg.PCAP.PCAPPacket]¶
Iterates through the packets.
- Returns
Returns the next packet if available; otherwise returns
None
.- Return type
Optional[PCAPPacket]
See also
PCAPPacket
.
- Parse() → bool¶
Parses the format.
- Returns
Returns
True
if successful; otherwise returnsFalse
.- Return type
bool
See also
IteratePackets()
.
- class PCAPPacket¶
This class represents a single packet.
Methods:
Dump
(out)Outputs to a text stream information about the packet.
Returns the destination IP as string.
GetInfo
()Returns information about the packet as a string
Returns the protocol name.
Returns the source IP as string.
Attributes:
The packet buffer.
The captured length of the packet.
The ethernet data of the packet.
The IP data of the packet.
The length of the packet.
The offset of the packet.
The total size of the packet.
The timestamp of the packet.
- Dump(out: Pro.Core.NTTextStream)¶
Outputs to a text stream information about the packet.
- Parameters
out (NTTextStream) – The output stream.
See also
GetInfo()
.
- GetDestination() → str¶
- Returns
Returns the destination IP as string.
- Return type
str
See also
GetSource()
.
- GetInfo() → str¶
- Returns
Returns information about the packet as a string
- Return type
str
See also
Dump()
.
- GetProtocolName() → str¶
- Returns
Returns the protocol name.
- Return type
str
- GetSource() → str¶
- Returns
Returns the source IP as string.
- Return type
str
See also
GetDestination()
.
- buf¶
The packet buffer.
- caplen¶
The captured length of the packet.
- data¶
The ethernet data of the packet.
- ip¶
The IP data of the packet.
- len¶
The length of the packet.
- offset¶
The offset of the packet.
- size¶
The total size of the packet.
- timestamp¶
The timestamp of the packet.