批量Ping IP

    刚刚接触Python 想做点什么 听说Python 在网络方便很厉害 后来总结如下:

    第一:发现公司都固定IP 每次新来同事都要猜一个没有人用的IP  很费劲

    第二:我们公司有的IP可以上QQ 有的不可以所以我每次也要换IP O(∩_∩)O

    所以想到用Python 做一个批量Ping IP的工具 以至于方便于自 方便于人 少说多做  先上图 

 

原理很简单 什么语言都可以实现的  献丑了 上代码

 1 import subprocess
 2 import string
 3 import os
 4 import sys
 5 cmd="cmd.exe"
 6 
 7 type = sys.getfilesystemencoding()#解决中文乱码
 8 Section = int(raw_input("请输入正确IP段(例如:192.168.20.101,输入 20 即可) ").decode('UTF-8').encode(type)) #客户数据IP段数值
 9 if Section>255:  #校验
10     print ("请输入正确IP段数据!").decode('UTF-8').encode(type)
11 
12 #客户起始数据IP数值
13 begin = int(raw_input("请输入查询起始IP  :").decode('UTF-8').encode(type)) 
14 if begin>255 or begin<0: #校验
15     print ("请输入正确起始IP").decode('UTF-8').encode(type)
16 
17 #客户结束数据IP数值
18 end = int(raw_input("请输入查询结束IP   :").decode('UTF-8').encode(type))
19 if end>255 or end<0: #校验
20     print ("请输入正确结束IP").decode('UTF-8').encode(type)
21 
22 #循环开始数据到结束IP值
23 while begin<=end:
24     return1 = os.system("ping -n 1 -w 1  192.168."+str(Section)+"."+str(begin)+"\n")  #每个ip ping1次,等待时间为1s
25     if return1:
26          print ('ping %s is fail'%str(begin)) #失败
27     else:
28          print ("ping %s is ok"%str(begin)) #成功
29     begin+=1

 

  应该还有很多方式去操作的方式  如果你有好的方式或意见 请您留下宝贵的意见!共建中国技术 共享中国代码 共同进步技术人生!

  Demo 下载地址:https://files.cnblogs.com/yhyjy/PingIP.zip

 

posted @ 2014-05-11 16:26  Elite_Y  阅读(7218)  评论(6编辑  收藏  举报