0

I am trying to fetch the ips from the ranges (172.16.3.20 to 192.168.1.1) using the following code but it is taking lot of time and cpu and sometimes it doesnt work at all. Is there any better way of finding it? Output required is as follows:
172.16.3.21
172.16.3.22 ...
...
192.167.255.255
192.168.1.1

Code:

start = list(map(int, start_ip.split(".")))  
end = list(map(int, end_ip.split(".")))   
ip_range = []  
temp = start  
ip_range.append(start_ip)  
while temp != end:    
    start[3] += 1  
    for i in (3, 2, 1):
       if temp[i] == 256:
          temp[i] = 0
          temp[i-1] += 1
    ip_range.append(".".join(map(str, temp)))

1 Answers1

0

Here you go:

from ipaddress import IPv4Address

start = IPv4Address('172.16.3.20') + 1
end = IPv4Address('192.168.1.1')
ips = []
while start <= end:
    ips.append(start)
    start += 1
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17