I have 2 CSV files. One with Hostnames and IPs. The second with IP information (Netmask, Cidr, Subnet Name etc..)
I currently have a situation like the following.
for i, ipAddress in CSV1:
for j, ipNetwork in CSV2:
if ipAddress in ipNetwork:
append ipNetwork['Subnet Name']
Unfortunately, the first csv has 9000 IPs and the second list has 30'000 subnets. This is taking a huge amount of time to iterate through. I know this was an awful way of implementing this but I knew I could always improve.
Can anyone advise how better I can solve this problem? How can I search through and compare elements in each to shorten the runtime of this script?
Here is the sample data
[CSV 1 - Sample IP]
IP Address
144.196.86.89
56.144.25.138
3.16.101.238
123.18.128.50
19.22.2.124
78.88.241.163
144.44.200.20
27.215.172.218
124.90.163.19
[CSV 2 - Sample Subnet Information]
address netmask Company Subnet Name Compartment Type cidr
10.2.1.0 255.255.255.0 UPS UPS Site 1 Desktop 10.2.1.0/24
10.2.2.0 255.255.255.0 UPS UPS Site 2 Desktop 10.2.2.0/24
10.2.3.0 255.255.255.0 UPS UPS Site 3 Desktop 10.2.3.0/24
10.2.4.0 255.255.255.0 UPS UPS Site 4 Desktop 10.2.4.0/24
10.2.5.0 255.255.255.0 UPS UPS Site 5 Desktop 10.2.5.0/24
10.2.6.0 255.255.255.0 UPS UPS Site 6 Desktop 10.2.6.0/24
10.2.7.0 255.255.255.0 UPS UPS Site 7 Desktop 10.2.7.0/24
10.2.8.0 255.255.255.0 UPS UPS Site 8 Desktop 10.2.8.0/24
10.2.10.0 255.255.254.0 UPS UPS Site 9 Desktop 10.2.10.0/23
10.2.12.0 255.255.255.0 UPS UPS Site 10 Desktop 10.2.12.0/24
10.2.13.0 255.255.255.0 UPS UPS Site 11 Desktop 10.2.13.0/24