import re
filename=open('ip.txt','r+')
fb=open('ipout.txt','w+')
def group(line,mode=0):
r = re.split("\s{2,}",line)
domain = r[0].strip()
ip = r[1].strip()
if mode == 0:
return domain
elif mode == 1:
return ip if len(ip)<16 else 0
def makeCList(tempIp,start=1,end=255):
return [tempIp+str(temp) for temp in range(start,end)]
iplist = []
for line in filename.readlines():
line = line.strip()
times = len(re.findall(r"\.",line))
if "-" in line:
start = re.split("-", line)[0]
end = re.split("-", line)[1]
if times == 3:
ip = re.match(r"(\d+\.\d+\.\d+\.)(\d+)", start.strip())
start = int(ip.group(2))
end = int(end.strip())
iplist += makeCList(ip.group(1),start=start,end=end+1)
for ip in iplist:
print(ip)
fb.writelines(ip+'\n')
使用方法
在同一文件夹下放入代码和ip.txt
运行cmd
输出结果
看什么呢,还不点赞加收藏。