一个用于解析pcap文件的python库
Project description
pypcaptools介绍
pypcaptools 是一个用于处理pcap文件的 Python 库,可以实现以下功能:
- 将流量按照session进行分隔,可以输出pcap格式或json格式。
安装
pip install pypcaptools
Quick Start
- 分流
from pypcaptools import PcapHandler
origin_pcap = "/path/dir/filename"
ph = PcapHandler(origin_pcap)
output_dir = "/path/dir/output_dir"
# 分流之后以pcap格式输出,TCP流允许从中途开始(即没有握手过程)
session_num, output_path = ph.split_flow(output_dir, tcp_from_first_packet=False, output_type="pcap")
# 分流之后以json格式输出,输出一个json文件,其中每一个单元表示一条流,TCP流必须从握手阶段开始,从中途开始的TCP流会被丢弃
session_num, output_path = ph.split_flow(output_dir, tcp_from_first_packet=True, output_type="json")
- 将流量分流并加入到mysql数据库中
from pypcaptools import PcapToDatabaseHandler
db_config = {
"host": "",
"port": 3306,
"user": "root",
"password": "password",
"database": "traffic",
"table": "table",
}
# 参数依次为 处理的pcap路径、mysql配置、应用层协议类型、访问网站/行为、采集机器、table注释
handler = PcapToDatabaseHandler(
"test.pcap", db_config, "https", "github.com", "vultr10", "测试用数据集"
)
handler.split_flow_to_database()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pypcaptools-1.3.tar.gz
(6.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypcaptools-1.3.tar.gz.
File metadata
- Download URL: pypcaptools-1.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a98641d854f83bff3bcbe90f8476158f7437bd6f4135bd83428927f9aa827f7e
|
|
| MD5 |
5e53f82fe7f1c435ded9584c1c7c71cc
|
|
| BLAKE2b-256 |
d2d4b13a7b433ecb7a80763b25419d572fd6e72f4afbe974d7dc41884ebc63b1
|
File details
Details for the file pypcaptools-1.3-py3-none-any.whl.
File metadata
- Download URL: pypcaptools-1.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363d92da372a115bfbfcca1623e892907e4654299c88d0131b8f1afb1824b1cf
|
|
| MD5 |
25b4da6a4b6d08137d1cb26a457e223b
|
|
| BLAKE2b-256 |
4acecf7f0dfc859077400727f1665c59dd8f35d395a6da314d21fb8f1d439427
|