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

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.

Files for django-middlewall, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size django_middlewall-0.1.2-py2.py3-none-any.whl (5.4 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size django-middlewall-0.1.2.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page