MFD Packet Capture
Module for Packet Capture support, module implements mfd-base-tool. Within the module, there are wrappers written for tcpdump, tshark & pktcap tools.
OS supported:
- WINDOWS (tshark)
- FREEBSD (tshark)
- LINUX (tcpdump, tshark)
- ESXI (tcpdump, pktcap)
Tshark Usage
from mfd_packet_capture import Tshark
from mfd_connect import RPyCConnection
# establish connection via mfd-connect
connection = RPyCConnection(ip="10.10.10.10")
tshark = Tshark(connection=connection, absolute_path_to_binary_dir = "C:\\tshark\\", interface_name="eth0")
version = tshark.get_version()
tshark_process = tshark.start()
time.sleep(2)
result = tshark.stop(tshark_process, expected_output=True)
For Windows pass network interface in quote, e.g.:
tshark_process = tshark.start(filters='-i "Ethernet 2"', additional_args="-l")
API documentation
-
Tshark(connection: Connection, interface_name: str = "", absolute_path_to_binary_dir: "Path | str | None" = None- Initializes Tshark instance on given connection and optionally interface name. Ifinterface_nameis not given on initialization, it can be passed throughtshark.start(filters="-i interface_name") -
start(*, capture_filters: str = "", filters: str = "", additional_args: str = "") -> "RemoteProcess"- Start TShark process with given filters and additional args.
Capture filters will be passed with-fparam to TShark.
RaisesTsharkExceptionif tshark command fails on execution, if passed incorrect args or if interface_name was defined and another interface is passed intshark.start(filters) -
stop(process: "RemoteProcess", *, expected_output: bool) -> List[str]- Stop tshark process and report result. raisesTsharkException: If process after stop and kill is still running or unexpectedly returned output or does not returned output when expected.
Tcpdump Usage
from mfd_packet_capture import Tcpdump
from mfd_connect import RPyCConnection
# establish connection via mfd-connect
connection = RPyCConnection(ip="10.10.10.10")
tcpdump = Tcpdump(connection=connection, interface_name="eth0")
version = tcpdump.get_version()
tcpdump_process = tcpdump.start(additional_args="-l")
time.sleep(2)
result = tcpdump.stop(tcpdump_process, expected_output=True)
API Documentation
-
Tcpdump(connection: Connection, interface_name: str = "", absolute_path_to_binary_dir: "Path | str | None" = None- Initializes Tcpdump instance on given connection and optionally interface name. Ifinterface_nameis not given on initialization, it can be passed throughtcpdump.start(filters="-i interface_name") -
start(*, filters: str = "", additional_args: str = "", namespace: str | None = None) -> "RemoteProcess"- Start Tcpdump process with given filters and additional args. RaisesTcpdumpExceptionif tcpdump command fails on execution, if passed incorrect args or if interface_name was defined and another interface is passed intcpdump.start(filters) -
stop(process: "RemoteProcess", *, expected_output: bool) -> List[str]- Stop tcpdump process and report result. RaisesTcpdumpException: If process after stop and kill is still running or unexpectedly returned output or did not return output when expected. -
read_tcpdump_packets(file_path: Path, additional_args: str="-nvv", namespace: str | None = None) -> list[str]- Read packets from file which was created with other tools e.g pktcap-uw in pcap or pcapng format. RaisesTcpdumpException: If givenfile_pathwas not found
PktCap usage
import logging
from time import sleep
from mfd_connect import RPyCConnection
from mfd_packet_capture.pktcap import PktCap
logging.basicConfig(level=logging.DEBUG)
conn = RPyCConnection(ip="10.10.10.10")
pkt_capture = PktCap(connection=conn, interface_name="vmnic0")
# start capturing
process = pkt_capture.start(additional_args="--count 4")
sleep(10)
# stop capturing
output = pkt_capture.stop(process=process, expected_output=True)
logging.debug(f"output: {output}")
API Documentation
-
PktCap(connection: Connection, interface_name: str = "", absolute_path_to_binary_dir: "Path | str | None" = None- Initializes PktCap instance on given connection and optionally interface name. Ifinterface_nameis not given on initialization, it can be passed throughpktcap.start(interface_name="interface_name") -
start(interface_name: str, additional_args: Optional[str] = "") -> RemoteProcess: to start capturing packets via pktcap-uw. RaisesPktCapExceptionif command fails on execution or if interface name was given both on initialization and asstart()argument. -
stop(process: RemoteProcess, *, expected_output: bool) -> List[str]: stop pktcap-uw process and get its output (combined stdout & stderr). RaisesPktCapExceptionif process after stop and kill is still running or if there is no output but expected_output is set to True.
If you encounter any bugs or have suggestions for improvements, you're welcome to contribute directly or open an issue here.
Metadata
Release files for mfd-packet-capture 2.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mfd_packet_capture-2.16.0-py3-none-any.whl | Python 3 | none | any | Details for mfd_packet_capture-2.16.0-py3-none-any.whl |
Release files / mfd_packet_capture-2.16.0-py3-none-any.whl
| Download URL | mfd_packet_capture-2.16.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
397602343a55df1e9adde69dee4fa311a2dc0d999057a826261708593d9f5bab
|
|
BLAKE2b-256 checksum How to use checksums |
6967faf5309bd4c53624510715ae67111108376beb3837643ad5e6eb301264a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for mfd-packet-capture 2.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.