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


上一篇:SpringMVC配置全局过滤编码问题


下一篇:python文件操作中的坑