I have a dataframe with IPv4 and IPv6 CIDR IP address ranges (these can be split up if necessary) in a data frame. I am hoping to take those ranges and create a data frame with each address in the range, so I can join that with another data frame to do some filtering.
Using the ipaddress package, the function to expand a list is:
a = ip.ip_network('103.21.244.0/22')
for x in a.hosts():
print(x)
This yields a list for just this IP range. Does anyone know how to put in a series of CIDR ranges so I don't have to perform the above n times? If I put a reference to the data frame in place of the IP address above, I get a ValueError stating that it doesn't appear to be an IPv4 or IPv6 network.
The secondary question, as a Python newbie, what do I need to do to get these expanded ranges into a list or data frame? I tried this:
a = ip.ip_network('103.21.244.0/22')
ip_list = [] #x for x in a.hosts()
for x in a.hosts():
ip_list.append(x)
ip_list
And ended up with:
[IPv4Address('103.21.244.1'),
IPv4Address('103.21.244.2'),
IPv4Address('103.21.244.3'),
IPv4Address('103.21.244.4'),
IPv4Address('103.21.244.5'),
...]
I'm sure there is a better way than taking that output and regexing the IP addresses.