kkroesch
1/28/2019 - 2:55 PM

Iterate IP range

Iterate IP range

from ipaddress import ip_address

""" Two IP addresses are known """
start = ip_address('192.168.1.0')
end = ip_address('192.168.1.254')
print("From {} to {}".format(start, end))
for ip in range(int(start), int(end)):
    print(ip_address(ip))

""" Network address is known """
from ipaddress import ip_network
list(ip_network('192.0.2.0/29').hosts())