Extraction Options

pcapkit.foundation.options contains the options classes Extractor and extract() take as dump, reassembly, traceflow and stream, one per feature. pcapkit and pcapkit.interface export them.

class pcapkit.foundation.options.DumpOptions(*, fout, format='tree', files=False, extension=True)[source]

Bases: Info

Output settings of an Extractor.

Parameters:
  • fout (str) – output file name, or under files the directory the files go in

  • format (Literal['pcap', 'cap', 'pcapng', 'json', 'tree', 'text', 'txt', 'plist', 'xml']) – output file format, a key of Extractor.__output__

  • files (bool) – whether each frame is dumped to a file of its own

  • extension (bool) – whether the format’s file extension is appended to fout when it lacks one; not under files

Raises:

RegistryError – If fout is not a str.

Added in version 1.7.0.

fout: str

Output file name, or the directory under files.

format: Literal['pcap', 'cap', 'pcapng', 'json', 'tree', 'text', 'txt', 'plist', 'xml']

Output file format.

files: bool

Whether each frame is dumped to a file of its own.

extension: bool

Whether the format’s file extension is appended to fout.

class pcapkit.foundation.options.ReassemblyOptions(*, protocols, strict=True, store=True, timeout=None)[source]

Bases: Info

Reassembly settings of an Extractor.

Parameters:

An Extractor given no names turns the feature off, as None does, and warns that it does.

Raises:

RegistryError – If protocols is not a list of names.

Added in version 1.7.0.

protocols: tuple[str, ...]

Names of the reassemblers to enable, lower-cased, each once.

strict: bool

Whether an incomplete datagram is reported as its received runs.

store: bool

Whether reassembled datagrams are stored.

timeout: float | None

Reassembly timeout in seconds, or None for each protocol’s own.

class pcapkit.foundation.options.TraceFlowOptions(*, protocols, fout='./tmp', format='pcap', byteorder=sys.byteorder, nanosecond=False, bidirectional=True, analyze=False, timeout=None)[source]

Bases: Info

Flow tracing settings of an Extractor.

Parameters:
  • protocols (Iterable[str]) – names of the flow tracers to enable, as registered in Extractor.__traceflow__, matched lower-cased

  • fout (str) – output root path

  • format (str) – output file format

  • byteorder (Literal['big', 'little']) – output file byte order

  • nanosecond (bool) – output nanosecond-resolution file flag

  • bidirectional (bool) – whether both halves of a conversation are traced as one flow; False traces a flow per direction

  • analyze (bool) – whether each traced flow reassembles its application layer, so that its packet can be read. Off by default, because it buffers every traced payload – a cost tracing does not otherwise pay. Unavailable on the pyshark engine, which reports dissected fields rather than the octets behind them

  • timeout (float | None) – idle timeout in seconds, measured on the capture’s own clock: a flow none of whose packets is more recent is finalised, as TraceFlow.advance does; None keeps every flow until the end of the capture

An Extractor given no names turns the feature off, as None does, and warns that it does.

Raises:

RegistryError – If protocols is not a list of names.

Added in version 1.7.0.

Changed in version 1.10.0: Takes timeout (#2956).

protocols: tuple[str, ...]

Names of the flow tracers to enable, lower-cased, each once.

fout: str

Output root path.

format: str

Output file format.

byteorder: Literal['big', 'little']

Output file byte order.

nanosecond: bool

Output nanosecond-resolution file flag.

bidirectional: bool

Whether both halves of a conversation are one flow.

analyze: bool

Whether each traced flow reassembles its application layer.

timeout: float | None

Idle timeout in seconds, on the capture’s clock, or None.

Added in version 1.10.0.

class pcapkit.foundation.options.StreamOptions(*, buffer_size=io.DEFAULT_BUFFER_SIZE, buffer_save=False, buffer_path=None, no_eof=False)[source]

Bases: Info

Input stream settings of an Extractor.

The buffer settings apply to an input that cannot seek, such as a pipe, which is read through a SeekableReader.

Parameters:
  • buffer_size (int) – buffer size for reading the input

  • buffer_save (bool) – whether the buffered input is saved to a file

  • buffer_path (str | None) – path of that file; None uses a temporary file, deleted when the input is closed

  • no_eof (bool) – whether to not raise EOFError at the end of the input but retry instead, which is what a live capture on a pipe or on standard input wants, since a read there blocks until the writer produces more or closes. Retrying stops as soon as one retry finds nothing new, so an exhausted input finishes rather than spinning; on a seekable input, where nothing blocks, that means a file still being appended to ends at the data present when the extraction reached it

Added in version 1.7.0.

buffer_size: int

Buffer size for reading the input.

buffer_save: bool

Whether the buffered input is saved to a file.

buffer_path: str | None

Path of that file, or None for a temporary one.

no_eof: bool

Whether reaching the end of the input retries rather than stops.