I have a list of client IPs and a list of subnetworks like so:
ips = ['firstIP','secondIP',....]
subnets = ['subnet1', 'subnet2',.....]
My ultimate goal is to find which subnetwork has at least one client who belongs to it.
Using what I saw here I created this function:
def ip_in_network(ips, network):
for ip in ips:
if ipaddress.ip_address(ip) in ipaddress.ip_network(network):
return True
return False
lst = []
for network in subnets:
if ip_in_network(ips, network):
lst.append(network)
where ips
is the list of ips that I have and network
is an element from the list subnets
.
Both my lists are very large and I would like to make this more efficient using parallel programing. I am contemplating between using the threading
module and the multiprocessing
module because I understand that one more suited for network bound problems and the other for CPU computations.
So my question is, is the line ipaddress.ip_address(ip) in ipaddress.ip_network(network)
preforming some network requests or is it all running locally? I couldn't find out from the documatation. Thanks in advance!