标签:Python pcaplib 编程 ts len filename packet file
https://pythonhosted.org/pcaplib/api.html
The pcaplib API reference
- class
pcaplib.
Reader
(filename)[source] -
Construct a Reader which reads the content of a PCAP file and can be consumed as an Iterable. An
FileFormatError
is raised if the file is not a valid PCAP file.Example:
import pcaplib pcap_reader = pcaplib.Reader('capture.pcap') for ts in pcap_reader: print(packet) (1494608771, 459378, 6, 6, b'\\x00\\x0c)\\xaa4\\xc9') (1494608771, 459556, 6, 6, b'\\x00\\x0c)\\xaa4\\xc9')
filename
-
a filename.
version_major
-
Major version, currently
2
.
version_minor
-
Minor version, currently
4
.
thiszone
-
the correction time in seconds between GMT (UTC) and the local timezone of the following packet header timestamps. In practice, time stamps are always in GMT, so thiszone is always
0
.
sigfigs
-
in theory, the accuracy of time stamps in the capture; in practice, all tools set it to
0
.
snaplen
-
the snapshot length for the capture (typically
65535
or even more, but might be limited by the user).
network
-
link-layer header type.
ts_sec
-
the date and time when this packet was captured. This value is in seconds since January 1, 1970 00:00:00 GMT.
ts_usec
-
the microseconds when this packet was captured, as an offset to
ts_sec
.
- class
pcaplib.
Writer
(filename, packets_iterable, network=<Network.EN10MB: 1>, big_endian=True)[source] -
Construct a Writer which will write in filename packets using the PCAP format.
Example:
import pcaplib pkt_list = [ (1494608771, 459378, 6, 6, b'\\x00\\x0c)\\xaa4\\xc9'), (1494608771, 459556, 6, 6, b'\\x00\\x0c)\\xaa4\\xc9'), ] pcap_writer = pcaplib.Writer('capture.pcap', pkt_list) pcap_writer.writer()
Parameters: - filename (str) – a filename
- packets_iterable (iterable) – An iterable of 5-tuples, each tuple should have the following format (
ts_sec
,ts_usec
,incl_len
,orig_len
,pkt_data
) - network – the network type, defaults to Ethernet
Network.EN10B
or1
.
packets_iterable.
-
An iterable of 5-tuples,
write
()[source]-
Iterates over
packets_iterables
and writes the content in a PCAP file.
Custom Enum
- class
pcaplib.
Network
(IntEnum)[source] -
An enumeration.
An IntEnum representing the network types
Custom Exceptions
- exception
pcaplib.
FileFormatError
(Exception)[source] -
Error if the file is not a valid PCAP file
标签:Python,pcaplib,编程,ts,len,filename,packet,file 来源: https://www.cnblogs.com/songhaibin/p/13678268.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。