Simple middleware for filtering requests by their source IP address
Project description
Simple middleware for blocking requests by IP Address
Quickstart
Install Django Middlewall:
pip install django-middlewall
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'middlewall.apps.MiddlewallConfig',
...
)
Enable middleware components:
# enable both white and black listing
MIDDLEWARE = [
'middlewall.middleware.BlacklistMiddleware',
'middlewall.middleware.WhitelistMiddleware',
...
]
Define access lists in CIDR notation:
# only allow requests from these subnets
MIDDLEWALL_WHITELIST = ['192.0.2.0/24', '198.51.100.0/24']
# also block this specific address
MIDDLEWALL_BLACKLIST = ['192.0.2.1/32']
(optional) Define a custom function to get remote addresses from request objects:
# take advantage of the X_FORWARDED_FOR support in ipware
MIDDLEWALL_ADDRESS_GETTER = 'ipware.ip.get_ip'
Running Tests
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -e .[test] (myenv) $ pip install tox (myenv) $ tox
Credits
History
0.1.1 (2017-03-09)
First release.
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
Close
Hashes for django_middlewall-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbeede1c5dfa60431558705d5518188709c5e5d62607b531b0e945720837e80d |
|
MD5 | 955ce2f2924deb91d3ab7a6ac4655d8e |
|
BLAKE2b-256 | 35a3733794bbf3793f4a956cf672eb40f2542c4bc4b3ca6df46fa7531c11e40f |