# PyWFP
PyWFP is a Python interface for working with Windows Filtering Platform (WFP), allowing creation of network traffic filters using a similar Windivert-style syntax.
> **Note:** PyWFP requires administrator privileges to run. Running without admin rights will result in a `WFPError` with code `0x00000005` (Access Denied).
## Installation
```bash
pip install pywfp
```
## Usage
```python
from pywfp import PyWFP
from pprint import pprint
def main():
# Create PyWFP instance
pywfp = PyWFP()
# Example filter string
filter_string = (
"outbound and tcp and remoteaddr == 192.168.1.3-192.168.1.4 " "and tcp.dstport == 8123 and action == block"
)
try:
# Use context manager to handle WFP engine session
with pywfp.session():
# Add the filter
filter_name = "PyWFP Block Filter"
pywfp.add_filter(filter_string, filter_name=filter_name, weight=1000)
# List existing filters
filters = pywfp.list_filters()
print(f"Found {len(filters)} WFP filters")
# Find our specific filter
if filter := pywfp.get_filter(filter_name):
print(f"Found filter: {filter}")
pprint(filter)
# Keep the filter active until interrupted
print("Press Ctrl+C to exit and remove the filter")
try:
while True:
input()
except KeyboardInterrupt:
print("Received Ctrl+C, cleaning up")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
```
## Supported Filters
PyWFP supports a variety of filter conditions that can be combined using logical AND operations. Here are the supported filter types:
### Basic Filter Syntax
```python
"outbound and tcp and remoteaddr == 192.168.1.3-192.168.1.4 and tcp.dstport == 8123 and action == allow"
```
### Supported Conditions
| Field | Description | Example Values |
|------------------|--------------------------------------------------|------------------------------------|
| inbound/outbound | Direction of traffic | `inbound`, `outbound` |
| tcp/udp/icmp | Protocol type | `tcp`, `udp`, `icmp` |
| remoteaddr | Remote IP address (supports ranges) | `192.168.1.1`, `10.0.0.1-10.0.0.255` |
| localaddr | Local IP address (supports ranges) | `127.0.0.1`, `192.168.1.1-192.168.1.255` |
| tcp.dstport | TCP destination port | `80`, `443` |
| tcp.srcport | TCP source port | `5000`, `8080` |
| udp.dstport | UDP destination port | `53`, `123` |
| udp.srcport | UDP source port | `5000`, `8080` |
| action | Filter action (allow/block) | `allow`, `block` |
### IP Address Ranges
You can specify IP ranges using hyphen notation:
```python
"remoteaddr == 192.168.1.1-192.168.1.255"
```
### Multiple Conditions
Combine conditions using AND:
```python
"outbound and tcp and remoteaddr == 192.168.1.1 and tcp.dstport == 80"
```
## Filter Management
```python
# You can set the weight of the filter to determine its priority. If weight is not specified, the highest priority will be given.
pywfp.add_filter("inbound and udp", filter_name="Block UDP", weight=500)
# List all filters
for filter in pywfp.list_filters():
print(filter["name"])
)
# Maybe more to be added here
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pywfp",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "windows, filtering, network, firewall",
"author": null,
"author_email": "Adrian Pitigoi <adrian.pitigoi90@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/41/02/9f6f46151244591347058538fc30a2c84e1b5df2b0614f5b5db6ce7c3856/pywfp-0.1.3.tar.gz",
"platform": null,
"description": "# PyWFP\n\nPyWFP is a Python interface for working with Windows Filtering Platform (WFP), allowing creation of network traffic filters using a similar Windivert-style syntax.\n\n> **Note:** PyWFP requires administrator privileges to run. Running without admin rights will result in a `WFPError` with code `0x00000005` (Access Denied).\n\n## Installation\n\n```bash\npip install pywfp\n```\n\n## Usage\n\n```python\nfrom pywfp import PyWFP\nfrom pprint import pprint\n\n\ndef main():\n # Create PyWFP instance\n pywfp = PyWFP()\n\n # Example filter string\n filter_string = (\n \"outbound and tcp and remoteaddr == 192.168.1.3-192.168.1.4 \" \"and tcp.dstport == 8123 and action == block\"\n )\n\n try:\n # Use context manager to handle WFP engine session\n with pywfp.session():\n # Add the filter\n filter_name = \"PyWFP Block Filter\"\n pywfp.add_filter(filter_string, filter_name=filter_name, weight=1000)\n\n # List existing filters\n filters = pywfp.list_filters()\n print(f\"Found {len(filters)} WFP filters\")\n\n # Find our specific filter\n if filter := pywfp.get_filter(filter_name):\n print(f\"Found filter: {filter}\")\n pprint(filter)\n\n # Keep the filter active until interrupted\n print(\"Press Ctrl+C to exit and remove the filter\")\n try:\n while True:\n input()\n except KeyboardInterrupt:\n print(\"Received Ctrl+C, cleaning up\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n## Supported Filters\n\nPyWFP supports a variety of filter conditions that can be combined using logical AND operations. Here are the supported filter types:\n\n### Basic Filter Syntax\n```python\n\"outbound and tcp and remoteaddr == 192.168.1.3-192.168.1.4 and tcp.dstport == 8123 and action == allow\"\n```\n\n### Supported Conditions\n| Field | Description | Example Values |\n|------------------|--------------------------------------------------|------------------------------------|\n| inbound/outbound | Direction of traffic | `inbound`, `outbound` |\n| tcp/udp/icmp | Protocol type | `tcp`, `udp`, `icmp` |\n| remoteaddr | Remote IP address (supports ranges) | `192.168.1.1`, `10.0.0.1-10.0.0.255` |\n| localaddr | Local IP address (supports ranges) | `127.0.0.1`, `192.168.1.1-192.168.1.255` |\n| tcp.dstport | TCP destination port | `80`, `443` |\n| tcp.srcport | TCP source port | `5000`, `8080` |\n| udp.dstport | UDP destination port | `53`, `123` |\n| udp.srcport | UDP source port | `5000`, `8080` |\n| action | Filter action (allow/block) | `allow`, `block` |\n\n### IP Address Ranges\nYou can specify IP ranges using hyphen notation:\n```python\n\"remoteaddr == 192.168.1.1-192.168.1.255\"\n```\n\n### Multiple Conditions\nCombine conditions using AND:\n```python\n\"outbound and tcp and remoteaddr == 192.168.1.1 and tcp.dstport == 80\"\n```\n\n## Filter Management\n```python\n# You can set the weight of the filter to determine its priority. If weight is not specified, the highest priority will be given.\npywfp.add_filter(\"inbound and udp\", filter_name=\"Block UDP\", weight=500)\n\n# List all filters\nfor filter in pywfp.list_filters():\n print(filter[\"name\"])\n)\n# Maybe more to be added here\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package for Windows Filtering Platform management",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/adrianpitigoi/pywfp",
"Repository": "https://github.com/adrianpitigoi/pywfp.git"
},
"split_keywords": [
"windows",
" filtering",
" network",
" firewall"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ab56fcd8432db78fb25248cc7f6e7a6445913d45deafb1930a55941072b47341",
"md5": "5adcd713e86e7d06461a1d7acfbcc8b9",
"sha256": "1f376cae1712cd4922e08881b345f89e929ae9a4963297cb0583c94417bc4520"
},
"downloads": -1,
"filename": "pywfp-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5adcd713e86e7d06461a1d7acfbcc8b9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 15766,
"upload_time": "2025-02-03T10:53:54",
"upload_time_iso_8601": "2025-02-03T10:53:54.137560Z",
"url": "https://files.pythonhosted.org/packages/ab/56/fcd8432db78fb25248cc7f6e7a6445913d45deafb1930a55941072b47341/pywfp-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "41029f6f46151244591347058538fc30a2c84e1b5df2b0614f5b5db6ce7c3856",
"md5": "9e4b551716e2acc725e5e781dc97c459",
"sha256": "f3703676219c2c910bab2f7b5cadfc37de10e0460741e5d813a03e6a4ecdcb26"
},
"downloads": -1,
"filename": "pywfp-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "9e4b551716e2acc725e5e781dc97c459",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 15130,
"upload_time": "2025-02-03T10:53:55",
"upload_time_iso_8601": "2025-02-03T10:53:55.784348Z",
"url": "https://files.pythonhosted.org/packages/41/02/9f6f46151244591347058538fc30a2c84e1b5df2b0614f5b5db6ce7c3856/pywfp-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-03 10:53:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adrianpitigoi",
"github_project": "pywfp",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "win32more",
"specs": [
[
"==",
"0.5.9"
]
]
}
],
"lcname": "pywfp"
}