PyDivert is a powerful Python binding for the WinDivert driver, enabling user-mode applications to capture, modify, and drop network packets on Windows. It offers features like advanced filtering, on-the-fly packet manipulation, and re-injection into the network stack. Version 3.1.0 is the current release, and the library demonstrates an active release cadence, with major updates supporting modern Python features (like asyncio) and WinDivert 2.2+ capabilities, including bundled driver binaries.
pip install pydivertVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to capture outbound TCP packets destined for port 80 and then re-inject them back into the network stack. It highlights the basic usage of `pydivert.WinDivert` as a context manager and iterating over captured packets. Remember to run this with administrator privileges.
Review the official PyDivert 3.x documentation and update `Packet` constructor calls and `wd_addr` usage to align with the new API. Ensure new metadata fields are handled if custom packet creation is performed.
Always run Python scripts or the application that uses PyDivert with administrator privileges (e.g., 'Run as administrator' on Windows).
Always remember to call `w.send(packet)` after processing a packet if you want it to proceed through the network stack. Implement logic to explicitly drop packets if that is the desired behavior.
Ensure your development and deployment environment is a supported Windows operating system. Consider alternative packet manipulation libraries if cross-platform compatibility is a requirement (e.g., `scapy` on Linux/macOS).
Implement robust input validation for all user-provided data, especially filter strings. Minimize the scope of administrator privileges for your application.
Install the module using pip: 'pip install pydivert'.
Uninstall and reinstall 'pydivert' to ensure all components are correctly installed: 'pip uninstall pydivert' followed by 'pip install pydivert'.
Install the 'pydivert' module using pip: 'pip install pydivert'.
Ensure that the 'Packet' object has the 'dst_port' attribute by verifying the packet's structure and the correctness of the code handling it.
Update 'pydivert' to the latest version compatible with your Python environment: 'pip install --upgrade pydivert'.