据说程序员,都要有个博客!而且要在这里,显得逼格比较高!!

据说程序员,都要有个博客!而且要在这里,显得逼格比较高!!好吧,我来了。

 

开始写脚本了!

 1 __author__ = 'armyz6666666'
 2 
 3 mark = "lease" #遍历文件找IP标记
 4 content = [] #存遍历处理的IP
 5 with open("dhcpd.leases","r",encoding="utf-8") as f:
 6     for line in f:
 7         if line.split(" ")[0] == mark:
 8             content.append(line.split(" ")[1]) #存到一个列表里
 9 content = set(content) #用集合,列表去重
10 print("------------------------")
11 while True:
12     ip = input("输入要查询的地址或不想查了按Q退出:")
13     #print(ip.split(".")[1]) #用。分割后对比
14     if ip == "q" or ip == "Q":
15         break
16     count = 0
17     for name in content:
18         if name.split(".")[1] == ip.split(".")[1] and name.split(".")[2] == ip.split(".")[2]:
19             print(name)
20             count = count + 1
21     print("你要查的地址C段是:%s。这段一共有%s地址" %(ip,count))
22     print("这个DHCP里一共分配的地址有:",len(content))

 


posted @ 2018-05-10 15:39  nb-深蓝的海  阅读(170)  评论(0编辑  收藏  举报