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

Posted armyz6666666

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了据说程序员,都要有个博客!而且要在这里,显得逼格比较高!!相关的知识,希望对你有一定的参考价值。

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

 

开始写脚本了!

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

 

以上是关于据说程序员,都要有个博客!而且要在这里,显得逼格比较高!!的主要内容,如果未能解决你的问题,请参考以下文章