import random
import collections
with open("ip.txt","w",encoding="utf-8") as file1:
for i in range(1200):
ip="172.25.254."+str(random.randint(1,255))+"\n"
file1.write(ip)
try:
with open("ip.txt","r",encoding="utf-8") as file2:
data=file2.readlines()
except FileNotFoundError:
print("文件不存在或被删除!")
c=collections.Counter(data)
c_list=c.most_common(10)
for key in c_list:
print("ip:{} 出现次数:{}".format(key[0].rstrip(),key[1]))
如有纰漏,请指正