Package: django-ip-restriction
Django IP RestrictionDepartment of International Trade Django IP Whitelist.  A Django middleware to restrict incoming IPs to a Django project to a list of allowed IPs or IP ranges.  Access to the admin login screen, and access to authenticated users are configurable, so it can be set such that users can authenticate, and bypass the IP restriction for the site.RequirementsPython >= 3.3Django >= 1.9Quick startInstall the package:$ pip install django-ip-restrictionAdd the middleware to your settings (Note: the minimum necessary other middleware components are Django’sSessionMiddlewareandAuthenticationMiddleware, these are added by default to your settings):# Django 1.9
MIDDLEWARE_CLASSES = [
    ...
    'ip_restriction.IpWhitelister',
    ...
]

# Django 1.10+
MIDDLEWARE = [
    ...
    'ip_restriction.IpWhitelister',
    ...
]ConfigurationTurning on or off, and configuring the IP whitelist is done either via variables in your Django settings, or via environment variables.  Values in Django settings take preference over values in the environment.Turning on/off the middleware is done viaRESTRICT_IPS, and the default value is False.  Either set this variable to True in Django settings, or set a truthy value (e.g. ‘true’, ‘1’) in your environment.Individual IPs can be whitelisted viaALLOWED_IPS, which is either a list of IP strings in Django settings, or a comma-separated list of IPs in the environment, e.g the following 2 are equivalent:# in bash (spaces are disregarded, trailing commas are OK)
export ALLOWED_IPS='192.168.0.1, 192.168.0.2,192.168.0.3,'

# in settings.py (will override the above environment variable)
ALLOWED_IPS = ['192.168.0.1', '192.168.0.2', '192.168.0.3']IP ranges can be whitelisted viaALLOWED_IP_RANGES, which is either a list of IP range strings (CIDR notation) in Django settings, or a comma-separated list of IP ranges in the environment, e.g.:# in bash
export ALLOWED_IP_RANGES='192.168.0.0/8, 127.0.0.0/2'

# in settings.py
ALLOWED_IPS = ['192.168.0.0/8', '127.0.0.0/2']Regardless of the IP addresses/rages that are in the whitelist, access for all authenticated users can be allowed withALLOW_AUTHENTICATED.  If true, this will allow any valid sessions past the IP restriction.Regardless of the IP addresses/rages that are in the whitelist, access to the admin URLs is also allowed past the IP restriction ifALLOW_ADMINis true.Setting bothALLOW_ADMINandALLOW_AUTHENTICATEDto true is recommended, and will allow any user that can log in, to first access only the admin interface in order to authenitcate, and from then have access to all URLs for the project.Restict Admin views onlyTo restrict admin views only set the variablesRESTRICT_ADMIN_BY_IPS,ALLOWED_ADMIN_IPSandALLOWED_ADMIN_IP_RANGESContributingContributions are welcome. Please follow the guidelines below to make life easier:Fork the repo, branch off release, make changes, then make a pull request (PR) to release on the main repoInclude documentation for any new featuresPlease limit changes for a PR to a single feature, or a single bugfixMake multiple PRs for multiple discrete changesPlease squash commits - ideally a single commit, but at least to a sensible minimumIf a PR reasonably should have multiple commits, consider if it shouldactuallybe separate PRsLicenseMIT licensed. See the bundledLICENSEfile for more
details.TODOAllow the IP restriction to work in a blacklisting mode, rather than just a whitelisting modeGet continuous integration to run on multiple python versions from 3.0+Currently only running on 3.5.0Utilise parallelismRun tests on multiple Django versionsCurrently only running against Django 1.9Utilise parallelism