ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

pcaplib Python版本的pcaplib的编程接口

2020-09-16 12:00:49  阅读:201  来源: 互联网

标签:Python pcaplib 编程 ts len filename packet file


https://pythonhosted.org/pcaplib/api.html

The pcaplib API reference

classpcaplib.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.

incl_len

the number of bytes of packet data actually captured and saved in the file. This value should never become larger than orig_len or the snaplen value of the global header.

orig_len

the length in bytes of the packet as it appeared on the network when it was captured. If incl_len and orig_len differ, the actually saved packet size was limited by snaplen.

classpcaplib.Writer(filenamepackets_iterablenetwork=<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_sects_usecincl_lenorig_lenpkt_data)
  • network – the network type, defaults to Ethernet Network.EN10B or 1.
packets_iterable.

An iterable of 5-tuples,

write()[source]

Iterates over packets_iterables and writes the content in a PCAP file.

Custom Enum

classpcaplib.Network(IntEnum)[source]

An enumeration.

An IntEnum representing the network types

Custom Exceptions

exceptionpcaplib.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. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有