Python ping ip
2015-11-12 09:55
585 查看
代码:
import subprocess
import string
import os
import sys
cmd="cmd.exe"
type = sys.getfilesystemencoding()#save code error
Section = int(raw_input("please input right IP(example:135.251.148.151,such as input 148) ").decode('UTF-8').encode(type)) #客户数据IP段数值
if Section>255: #check IP
print ("please input right IP!").decode('UTF-8').encode(type)
#client start IP
begin = int(raw_input("please input start IP :").decode('UTF-8').encode(type))
if begin>255 or begin<0: #check IP
print ("please input right start IP").decode('UTF-8').encode(type)
#client end IP
end = int(raw_input("please input end IP :").decode('UTF-8').encode(type))
if end>255 or end<0: #check IP
print ("please input right IP").decode('UTF-8').encode(type)
#start to ping from start ip to end ip
while begin<=end:
return1 = os.system("ping -n 4 -w 1 135.251."+str(Section)+"."+str(begin)+"\n") #every ip ping 4 times, wait time 1s
if return1:
print ('ping %s is fail'%str(begin)) #failed
else:
print ("ping %s is ok"%str(begin)) #success
begin+=1
运行结果:
please input right IP(example:135.251.148.151,such as input 148) 148
please input start IP :150
please input end IP :151
ping 150 is fail
ping 151 is ok
import subprocess
import string
import os
import sys
cmd="cmd.exe"
type = sys.getfilesystemencoding()#save code error
Section = int(raw_input("please input right IP(example:135.251.148.151,such as input 148) ").decode('UTF-8').encode(type)) #客户数据IP段数值
if Section>255: #check IP
print ("please input right IP!").decode('UTF-8').encode(type)
#client start IP
begin = int(raw_input("please input start IP :").decode('UTF-8').encode(type))
if begin>255 or begin<0: #check IP
print ("please input right start IP").decode('UTF-8').encode(type)
#client end IP
end = int(raw_input("please input end IP :").decode('UTF-8').encode(type))
if end>255 or end<0: #check IP
print ("please input right IP").decode('UTF-8').encode(type)
#start to ping from start ip to end ip
while begin<=end:
return1 = os.system("ping -n 4 -w 1 135.251."+str(Section)+"."+str(begin)+"\n") #every ip ping 4 times, wait time 1s
if return1:
print ('ping %s is fail'%str(begin)) #failed
else:
print ("ping %s is ok"%str(begin)) #success
begin+=1
运行结果:
please input right IP(example:135.251.148.151,such as input 148) 148
please input start IP :150
please input end IP :151
ping 150 is fail
ping 151 is ok
相关文章推荐
- python开发之for循环操作实例详解
- python之print实践
- Python xlrd、xlwt、xlutils修改Excel文件
- Python中map()函数浅析
- 用PDB库调试Python程序
- python开发之IDEL(Python GUI)的使用方法图文详解
- python学习笔记--更新
- 递归函数溢出---尾递归
- 【python】matplotlab在Windows下的安装
- python uniform()
- Python配置
- python 学习笔记2
- python开发之IDEL(Python GUI)的使用方法图文详解
- python开发之for循环操作实例详解
- 深入浅析Python字符编码
- python开发之字符串string操作方法实例详解
- python开发之函数定义实例分析
- Python中Class类用法实例分析
- python开发中module模块用法实例分析
- python开发中range()函数用法实例分析