-2

how do I make an IP range, for example my original IP there are the first 2 127.0.0.1 the second 128.0.0.1, I want if I use that IP for the IP range will be: 127.0.0.1 - 127.0.255.255 and so on, this my example code :

list_data = ["127.0.0.1", "128.0.0.1"]
for i in range(255):
    for j in range(255):
        ip = list_data+".%d.%d" % (i, j)
        print (sb+fg+'[RANGE-IP]   ===>   '+ip)
        open('IP.txt', 'a').write(ip + "\n")
gmps org
  • 23
  • 8

1 Answers1

0

That's pretty easy to achieve using this way

>>> import ipaddress
>>> [str(ip) for ip in ipaddress.IPv4Network('192.0.2.0/28')]
['192.0.2.0', '192.0.2.1', '192.0.2.2',
'192.0.2.3', '192.0.2.4', '192.0.2.5',
'192.0.2.6', '192.0.2.7', '192.0.2.8',
'192.0.2.9', '192.0.2.10', '192.0.2.11',
'192.0.2.12', '192.0.2.13', '192.0.2.14',
'192.0.2.15']

For your case it looks like IPv4Network('127.0.0.0/16')

Alexandr Shurigin
  • 3,921
  • 1
  • 13
  • 25