首页 > 其他 > 详细

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

时间:2018-05-10 16:14:40      阅读:152      评论:0      收藏:0      [点我收藏+]

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

 

开始写脚本了!

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

 

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

原文:https://www.cnblogs.com/armyz6666666/p/9019975.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!