A Python package for Windows Filtering Platform management
Project description
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
WFPErrorwith code0x00000005(Access Denied).
Installation
pip install pywfp
Usage
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
"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:
"remoteaddr == 192.168.1.1-192.168.1.255"
Multiple Conditions
Combine conditions using AND:
"outbound and tcp and remoteaddr == 192.168.1.1 and tcp.dstport == 80"
Filter Management
# 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
Testing
Unit Tests
Run unit tests with:
pytest -m "not integration"
Integration Tests
Integration tests require:
- Windows OS
- Administrator privileges
- Local network access
To run integration tests locally:
# Open an administrator command prompt
pytest -m integration
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
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 pywfp-0.1.42.tar.gz.
File metadata
- Download URL: pywfp-0.1.42.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46afcd562037bfdf035322f538fcb79143aacf02d7cb397acd67078b5fabca93
|
|
| MD5 |
160c6236bac34b66b19db9e1d099aafe
|
|
| BLAKE2b-256 |
bce4ae5f369e67c97bf7c586f8510fdae1b3a046eb787dbb66762f030eb11721
|
Provenance
The following attestation bundles were made for pywfp-0.1.42.tar.gz:
Publisher:
publish.yml on adrianpitigoi/pywfp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pywfp-0.1.42.tar.gz -
Subject digest:
46afcd562037bfdf035322f538fcb79143aacf02d7cb397acd67078b5fabca93 - Sigstore transparency entry: 168241804
- Sigstore integration time:
-
Permalink:
adrianpitigoi/pywfp@932a209f962ce36b9af7af4ea6429da9036a27ff -
Branch / Tag:
refs/tags/0.1.42 - Owner: https://github.com/adrianpitigoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@932a209f962ce36b9af7af4ea6429da9036a27ff -
Trigger Event:
release
-
Statement type:
File details
Details for the file pywfp-0.1.42-py3-none-any.whl.
File metadata
- Download URL: pywfp-0.1.42-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c22722ea246b0bcb19c8ef42e1afa33045172555d856087a94b288cc09f336d
|
|
| MD5 |
1d83fa93cd7a76dcfbc5d5cebe9db848
|
|
| BLAKE2b-256 |
19f42101a0ac3c47db64cf51f4904b7d9c980faa034dcac68f29700f0149a3a9
|
Provenance
The following attestation bundles were made for pywfp-0.1.42-py3-none-any.whl:
Publisher:
publish.yml on adrianpitigoi/pywfp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pywfp-0.1.42-py3-none-any.whl -
Subject digest:
6c22722ea246b0bcb19c8ef42e1afa33045172555d856087a94b288cc09f336d - Sigstore transparency entry: 168241806
- Sigstore integration time:
-
Permalink:
adrianpitigoi/pywfp@932a209f962ce36b9af7af4ea6429da9036a27ff -
Branch / Tag:
refs/tags/0.1.42 - Owner: https://github.com/adrianpitigoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@932a209f962ce36b9af7af4ea6429da9036a27ff -
Trigger Event:
release
-
Statement type: