-
Notifications
You must be signed in to change notification settings - Fork 0
/
range.py
28 lines (22 loc) · 632 Bytes
/
range.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
start_ip = sys.argv[1]
end_ip = sys.argv[2]
def ip_to_int(ip):
octets = ip.split('.')
return int(octets[0]) * 256**3 + int(octets[1]) * 256**2 + int(octets[2]) * 256 + int(octets[3])
def int_to_ip(num):
octet_d = num % 256
num //= 256
octet_c = num % 256
num //= 256
octet_b = num % 256
num //= 256
octet_a = num
return f"{octet_a}.{octet_b}.{octet_c}.{octet_d}"
start_int = ip_to_int(start_ip)
end_int = ip_to_int(end_ip)
with open("ip_list.txt", "w") as f:
for i in range(start_int, end_int + 1):
ip = int_to_ip(i)
f.write(ip + "\n")
print("Complete.")