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