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'])