Skip to main content

Simple middleware for filtering requests by their source IP address

Project description

https://badge.fury.io/py/django-middlewall.svg https://travis-ci.org/jmz-b/django-middlewall.svg?branch=master https://codecov.io/gh/jmz-b/django-middlewall/branch/master/graph/badge.svg

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.2 (2017-03-09)

  • General code clean up.

0.1.1 (2017-03-09)

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-middlewall-0.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

django_middlewall-0.1.2-py2.py3-none-any.whl (5.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-middlewall-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django-middlewall-0.1.2.tar.gz
Algorithm Hash digest
SHA256 91033c4e5cf41d234d39dfbf06cba2381bc6e6895ce818e158cfe2bf0edc28a0
MD5 a133d41b319b6eee590868dffcf7f1b8
BLAKE2b-256 f9d0630c8dfab2d89890e684f124446fa406be0b97aa146929eb9cd01c3877d3

See more details on using hashes here.

File details

Details for the file django_middlewall-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_middlewall-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4d57ae1df5f07d5bf2e81be86b9e7732f56b6d9c627a8e1f8b8c231b3182eaf2
MD5 e8e712078d38e071a548529d6561e905
BLAKE2b-256 a727b05bed9e82b54fec0df0783a11d0d8cab4528a71402629dd482e74a0b7ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page