IP聚合C段
作者:互联网
import re
def ip2c(ipNoDup):
ipset = set()
for ip in ipNoDup:
ipset.add(re.findall(r'\d+?\.\d+?\.\d+?\.',ip)[0] + '0/24')
iplist = list(ipset)
iplist.sort()
return iplist
with open('ip.txt','r',encoding='utf-8') as f:
lists = ''.join(f.readlines()).split('\n')
print(ip2c(lists))
with open('new_ip.txt','w',encoding='utf-8') as ff:
ff.writelines('\n'.join(ip2c(lists)))
标签:聚合,encoding,ipset,IP,lists,ip,iplist,ip2c 来源: https://blog.csdn.net/u010930278/article/details/121457815