Skip to content

Instantly share code, notes, and snippets.

@CCCougar
Created December 31, 2021 03:10
Show Gist options
  • Save CCCougar/8d12a638f2705c718da7f9b7ab00daf2 to your computer and use it in GitHub Desktop.
Save CCCougar/8d12a638f2705c718da7f9b7ab00daf2 to your computer and use it in GitHub Desktop.
Generate an IP range list in Python
# author: https://tkit.dev/2011/09/11/how-to-generate-an-ip-range-list-in-python/
def ipRange(start_ip, end_ip):
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
temp = start
ip_range = []
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)))
return ip_range
# sample usage
ip_range = ipRange("192.168.1.0", "192.171.3.25")
for ip in ip_range:
print(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment