Created
January 24, 2021 07:06
-
-
Save layou233/abd7e5dda3fa428c76523731bcdb7edf to your computer and use it in GitHub Desktop.
Expand IP ranges into a .txt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import version | |
if int(version[0])<3: | |
range=xrange | |
filename=input('File name(.txt): ')+'.txt' | |
with open(filename,'w') as file: | |
while True: | |
try: | |
ipstart,ipend=[i.split('.') for i in input('IP range(split by -): ').split('-')] | |
ipstart=[int(i) for i in ipstart] | |
ipend=[int(i) for i in ipend] | |
except ValueError: | |
print('[ValueError]Wrong input. Please retry.') | |
continue | |
bok=False | |
cok=False | |
doc=False | |
try: | |
for a in range(ipstart[0],ipend[0]+1): | |
bok=(ipstart[0]==ipend[0]) | |
for b in range(ipstart[1],ipend[1]+1 if bok else 256): | |
cok=((ipstart[1]==ipend[1]) and bok) | |
for c in range(ipstart[2],ipend[2]+1 if cok else 256): | |
dok=((ipstart[2]==ipend[2]) and cok) | |
for d in range(ipend(3)+1 if dok else 256): | |
file.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+'\n') | |
except IndexError: | |
print('[IndexError]Wrong input. Please retry.') | |
continue | |
print('Finished') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment