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)))