3 ms·
It also doesn't short-circuit as written since it uses a list comprehension. Switching to a generator solves that: def in_block(ip, block): ip_addr
by js2 10y ago
It also doesn't short-circuit as written since it uses a list comprehension. Switching to a generator solves that:
def in_block(ip, block):
ip_addr = IPAddress(ip)
return any(ip_addr in IPNetwork(cidr) for cidr in block)
Or just be explicit:
def in_block(ip, block):
ip_addr = IPAddress(ip)
for cidr in block:
if ip_addr in IPNetwork(cidr):
return True
return False