1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class CIDR_LIST(list):
def __init__(self, cidrs):
self.cidrs = []
try:
#http://cheeseshop.python.org/pypi/IPv4_Utils/0.35
import ipv4
for cidr in cidrs:
self.cidrs.append(ipv4.CIDR(cidr))
except ImportError:
pass
def __contains__(self, ip):
import ipv4
try:
for cidr in self.cidrs:
if ipv4.CIDR(ip) in cidr:
return True
except:
pass
return False
|
More like this
- Include entire networks in INTERNAL_IPS setting by pmclanahan 4 years, 2 months ago
- Internal view decorator by gsakkis 2 years, 10 months ago
- Globs for INTERNAL_IPS by kcarnold 4 years, 2 months ago
- IP Authorization Decorator with IP list by jansta 2 years, 3 months ago
- Middleware to prevent access to the admin when user ip not in INTERNAL_IPS by jezdez 2 years, 10 months ago
Comments