python 多线程检测同网段主机在线状态
2013-01-13 17:52
519 查看
# -*- coding: utf-8 -*-
#code by scpman
#http://www.scpman.com
import threading
from time import sleep,ctime
def ping_all(i,ip):
import os
#print ip
cmd="ping -n 1 "+ip+'|findstr TTL'
#print cmd
res=os.popen(cmd)
for res in res.readlines():
#print res
print 'HOST:',ip,'is alive!\n'
def main(ips,end):
print 'starting at:',ctime()
threads=[]
##########################
ips=ips+'.'
end=end
ip=[]
for s in range(end):
ip.append(ips+str(s))
nloops=range(len(ip))
####################
for i in nloops:
t=threading.Thread(target=ping_all,args=(i,ip))
threads.append(t)
for i in nloops:
threads[i].start()
for i in nloops:
threads[i].join()
print "all done at:",ctime()
##开始
main('10.10.29',255)
[/i][/i]
本文出自 “90后运维博客” 博客,请务必保留此出处http://scpman.blog.51cto.com/5060169/1117472
#code by scpman
#http://www.scpman.com
import threading
from time import sleep,ctime
def ping_all(i,ip):
import os
#print ip
cmd="ping -n 1 "+ip+'|findstr TTL'
#print cmd
res=os.popen(cmd)
for res in res.readlines():
#print res
print 'HOST:',ip,'is alive!\n'
def main(ips,end):
print 'starting at:',ctime()
threads=[]
##########################
ips=ips+'.'
end=end
ip=[]
for s in range(end):
ip.append(ips+str(s))
nloops=range(len(ip))
####################
for i in nloops:
t=threading.Thread(target=ping_all,args=(i,ip))
threads.append(t)
for i in nloops:
threads[i].start()
for i in nloops:
threads[i].join()
print "all done at:",ctime()
##开始
main('10.10.29',255)
[/i][/i]
本文出自 “90后运维博客” 博客,请务必保留此出处http://scpman.blog.51cto.com/5060169/1117472
相关文章推荐
- python检测主机状态
- python 多线程实现检测服务器在线情况
- python检测远程主机的端口状态
- python 多线程实现检测服务器在线情况
- shell 检测网段在线主机
- 使用python检测手机QQ在线状态的脚本代码
- Python检测QQ在线状态的方法
- 用python检测qq在线状态
- 批量探测一个网段内主机在线状态的脚本(初)
- Python检测QQ在线状态的方法
- python检测QQ在线状态脚本
- 扫描192.168.0网段内的主机的在线状态
- 使用python检测手机QQ在线状态的脚本代码
- Cacti Weathermap添加主机在线状态图示检测
- python3实现多线程ping一个网段
- 快速浏览Silverlight3 Beta:在线与离线状态检测 推荐
- 检测当前网段哪些IP是在线的
- Python实现批量检测HTTP服务的状态
- 用 java 检测主机连网状态--CTO
- python 实现多线程ping检测服务器情况