Support IP ranges in INTERNAL_IPS

 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

  1. Include entire networks in INTERNAL_IPS setting by pmclanahan 5 years, 1 month ago
  2. Globs for INTERNAL_IPS by kcarnold 5 years, 1 month ago
  3. Internal view decorator by gsakkis 3 years, 9 months ago
  4. Debug SQL Query in Template by dario.agliottone 1 year, 11 months ago
  5. Middleware to prevent access to the admin when user ip not in INTERNAL_IPS by jezdez 3 years, 9 months ago

Comments

(Forgotten your password?)