Finding & unpacking CIDR blocks inside list of tuples

43 Views Asked by At

I'm working with an exported list of file repositories and their corresponding lists of IP addresses from which they are allowed to accept uploads. It is a large list of tuples and it is formatted like so:

[('Repo1', '192.168.90.0/24','192.168.1.10'), ('Repo2', '10.3.1.0/24'), ('Repo3', '10.2.11.0/24','10.12.127.0/24','10.57.3.0/24')]

I imported the ipaddress module and used the ip_network function:

sample = ipaddress.ip_network('10.2.11.0/24')

for i in sample:
    print(i)

This is what I want but I am unsure of how to run it on nested elements in my big list of tuples.

How can I identify every element that has a CIDR block (not every one does and some have multiple), run this function to unpack it, and put the element back together?

End goal being to save it to a file like csv.

0

There are 0 best solutions below