pyshark-plus-plus is a Python library that provides a convenient interface for interacting with tshark, a command-line tool for capturing and analyzing network traffic. It enhances the capabilities of tshark by offering additional utilities, exception handling, and simplified methods for capturing network packets, listing interfaces, and analyzing .pcap files.
- Capture Network Traffic: Start and stop network packet captures with ease.
- Interface Listing: List available network interfaces by number, name, or description.
- PCAP Processing: Read, filter, and analyze
.pcapfiles for network traffic data. - Statistics Extraction: Retrieve detailed traffic statistics from captured files.
- Context Manager Support: Easily manage network capture sessions using Python's
withstatement.
-
From pip:
pip install pyshark-plus-plus
-
From gGitHub repository:
git clone https://github.com/your-username/pyshark-plus-plus.git cd pyshark-plus-plus -
Ensure
tsharkis installed on your system. You can download it from Wireshark's website.
from pyshark_plus_plus import TsharkWrapper
# Start a network capture on a specific interface
with TsharkWrapper(interface_number=1) as sniffer:
print("Capturing traffic...")
sniffer.start_capture(duration=10) # Capture traffic for 10 secondsYou can list the available interfaces using the following example:
from pyshark_plus_plus import TsharkWrapper
sniffer = TsharkWrapper()
print(sniffer.list_interfaces())For more examples, check out the examples directory.
pyshark-plus-plus/
│
├── examples/
│ ├── __init__.py
│ ├── list_available_interfaces.py # Example script for listing interfaces
│ └── sniff_from_localhost.py # Example script for capturing packets from localhost
│
├── pyshark_plus_plus/
│ ├── __init__.py
│ ├── exceptions.py # Custom exceptions for the library
│ ├── pyshark_plus_plus.py # Main wrapper class for interacting with tshark
│ └── statistics.py # Functions for processing capture statistics
│
├── tests/ # Unit tests for the library
│
├── venv/ # Virtual environment (optional)
│
├── LICENSE.txt # License information
├── CHANGELOG.md # Change history of the project
├── pyproject.toml # Configuration for building and packaging
├── README.md # Project documentation (this file)
└── tox.ini # Tox configuration for testingUnit tests are available in the tests directory.
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write tests for your changes.
- Submit a pull request.
This project is licensed under the MIT License - see the LICENSE.txt file for details.