PCAP Transformer
pcap-transformer is a Python package for extracting network flows from PCAP
files and transforming them into the feature formats used by ToN-IoT, BoT-IoT,
UNSW-NB15, and CSE-CIC-IDS2018 or by using different flow extraction external tools.
Installation
Python 3.12 or later is required:
pip install pcap-transformer
or
python -m pip install pcap-transformer
Install optional Python dependencies for all supported extractors with:
python -m pip install "pcap-transformer[all]"
You can install only the extras you need: nfstream, cicflowmeter,
ownprep, or nexusflowmeter. These extras install Python dependencies,
not the external system programs listed below.
External tools
Install the system programs required by the extractor you use:
| Extractor | External requirements |
|---|---|
| Zeek | Zeek; capinfos, tcpdump, and editcap for PCAP checks/conversion |
| Argus | Argus and ra; file and editcap for PCAPNG conversion |
| CICFlowMeter | A compatible CICFlowMeter wrapper configured with CICFLOWMETER_BIN |
| ownprep | TShark, used by PyShark |
| NFStream | System packet-capture libraries as required by NFStream |
| NexusFlowMeter | The nexusflowmeter executable from its optional Python extra |
The CICFlowMeter wrapper must accept a PCAP path and an output directory, and
write <pcap-filename>_Flow.csv into that directory. Check each external
tool's installation instructions and license. These extractors are generally
easiest to run on Linux or WSL.
Where to put the PCAP files
The job reads captures from:
<data_dir>/pcap/<src_dataset>/**/*.pcap
For example, with src_dataset="ToN_IoT" and data_dir pointing to the
project's data directory, put the input files here:
my_project/
├── run_transform.py
└── data/
└── pcap/
└── ToN_IoT/
├── capture1.pcap
└── capture2.pcap
The framework creates output below <data_dir>/flow/.
Important: The default data_dir="data" is relative to the process's
current working directory, which is the directory from which you run Python.
It is not automatically relative to the installed package or to your main
script. To always use a data directory next to a main script located in the
project root, resolve that path explicitly:
from pathlib import Path
from transforming_framework import Transform
PROJECT_ROOT = Path(__file__).resolve().parent
DATA_DIR = PROJECT_ROOT / "data"
job = Transform(
src_dataset="ToN_IoT",
goal_datasets="ToN_IoT",
data_dir=DATA_DIR,
)
job.run()
If the main script is inside a subdirectory such as scripts/, use
Path(__file__).resolve().parents[1] for the project root instead. You can
also pass an absolute path, for example data_dir=r"D:\datasets\my_project".
Run the script from PowerShell, for example:
python .\run_transform.py
Transformation modes
Import the public API with:
from transforming_framework import Transform
Choose exactly one mode: tools or goal_datasets. Each can be a string or a
list of strings.
Extract flows with selected tools
Tool mode extracts flow files without transforming them into a target dataset's feature format. Selected tools run sequentially:
job = Transform(
src_dataset="ToN_IoT",
tools=["zeek", "argus"],
data_dir=DATA_DIR,
)
job.run()
Supported tools are zeek, argus, cicflowmeter, nexusflowmeter,
ownprep, and nfstream.
Transform to a dataset format
Dataset mode chooses an extractor and transformer automatically:
goal_datasets |
Extractor(s) | Target format |
|---|---|---|
ToN_IoT |
Zeek | ToN-IoT |
BoT_IoT |
Argus | BoT-IoT |
UNSW_NB15 |
Argus and Zeek | UNSW-NB15 |
CSE_CIC_IDS2018 |
CICFlowMeter | CSE-CIC-IDS2018 |
Example:
job = Transform(
src_dataset="ToN_IoT",
goal_datasets="ToN_IoT",
data_dir=DATA_DIR,
)
job.run()
The source directory name and src_dataset value must match exactly.
Dataset feature definitions are included with the package.
Output locations
In tool mode, flow files and merged results are written under:
<data_dir>/flow/tool_convertion/<src_dataset>/<tool>/
In dataset mode, intermediate flow files and transformed outputs are written under:
<data_dir>/flow/dataset_format_convertion/<src_dataset>/<goal_dataset>/
For a ToN-IoT conversion, for example:
data/
└── flow/
└── dataset_format_convertion/
└── ToN_IoT/
└── ToN_IoT/
├── capture1.parquet
└── transformed/
├── capture1_transformed.parquet
└── merged/
├── merged.parquet
├── merged_preview.parquet
└── columns
The directory names tool_convertion and dataset_format_convertion are
spelled this way in the current output layout.
For UNSW-NB15, intermediate Argus and Zeek files are saved in separate directories and paired by filename. At least one matching pair is needed for the transformation.
Unlabeled output files
The framework does not assign labels or require ground-truth files. It merges
the extracted flows as-is; any existing label or Label column is excluded
from the merged output. Results are written directly under merged/:
merged.parquet: merged flow dataset.merged_preview.parquet: up to 50 sample rows per input file.columns: one output column name per line.
| Argument | Default | Description |
|---|---|---|
src_dataset |
Required | Source folder under <data_dir>/pcap/ |
tools |
None |
Tool(s) for extraction-only mode |
goal_datasets |
None |
Target feature format(s) for dataset mode |
data_dir |
"data" |
Root containing pcap/ and generated flow/ |
chunk_size_packets |
1_000_000 |
Packets per PCAP chunk |
max_size_pcap |
1_000_000_000 |
File-size threshold in bytes for splitting |
Large captures and reruns
Files larger than max_size_pcap are split with editcap into chunks of up
to chunk_size_packets. Chunks are stored next to each original PCAP in a
directory named <capture>_chunks_size_<chunk_size_packets>/. Existing chunk
directories are reused.
Existing flow and transformed Parquet files are skipped where possible, so a run can resume after interruption. Merged files and previews are rebuilt from the available Parquet files.
For more examples and a step-by-step guide, see README_FRAMEWORK.md.
License
This project is released under the MIT License. Checked-in CICFlowMeter sources and other third-party tools retain their own licenses. Third-party source files are not included in the pip distributions.
Metadata
Release files for pcap-transformer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pcap_transformer-0.1.1.tar.gz | 33.9 kB | Without provenance | Details for pcap_transformer-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pcap_transformer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pcap_transformer-0.1.1-py3-none-any.whl |
Total release size: 74.8 kB
Release files / pcap_transformer-0.1.1.tar.gz
| Download URL | pcap_transformer-0.1.1.tar.gz |
|---|---|
| Size | 33.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69ef4bb1d61ad9c3399512067827b11ba4382191a22d2fa24f409cb66ffb1f0f
|
|
BLAKE2b-256 checksum How to use checksums |
92af69a95def5592fa8449e64dfd5f598f77d41d950cd0ddc6041e0d8fe79681
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Release files / pcap_transformer-0.1.1-py3-none-any.whl
| Download URL | pcap_transformer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0be3369ca67572a38e2b5d2f1a4d3d3b6edaca7836a11a6cac8b164d669088ee
|
|
BLAKE2b-256 checksum How to use checksums |
803df07ecaeebc63b58cfdf50f8025044ec754f171f9316f31e596d09a42444d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Security for pcap-transformer 0.1.1
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.