Include entire networks in INTERNAL_IPS setting

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class IPList(list):

    def __init__(self, ips):
        try:
            #http://software.inl.fr/trac/wiki/IPy
            #ubuntu: apt-get install python-ipy
            from IPy import IP
            for ip in ips:
                self.append(IP(ip))
        except ImportError:
            pass
            
    def __contains__(self, ip):
        try:
            for net in self:
                if ip in net:
                    return True
        except:
            pass
        return False
            
INTERNAL_IPS = IPList(['127.0.0.1', '192.168.1.0/24'])

More like this

  1. Globs for INTERNAL_IPS by kcarnold 4 years, 2 months ago
  2. Support IP ranges in INTERNAL_IPS by jdunck 3 years, 4 months ago
  3. Middleware to prevent access to the admin when user ip not in INTERNAL_IPS by jezdez 2 years, 10 months ago
  4. Persistent Session Debugging with Django Debug Toolbar by brianjaystanley 1 year, 7 months ago
  5. IP Authorization Decorator with IP list by jansta 2 years, 3 months ago

Comments

kcarnold (on March 19, 2009):

If pulling in another external dependency is a bother, try #1380.

#

pmclanahan (on October 14, 2009):

kcarnold: That one is excellent for the most common case. I'll be using it. Thanks for the tip!

#

(Forgotten your password?)