没有合适的资源?快使用搜索试试~ 我知道了~
python多线程ping服务器在线情况
需积分: 50 14 下载量 3 浏览量
2017-06-30
14:33:02
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
3页
单个ping服务器太麻烦,多线程吧
资源推荐
资源详情
资源评论
python 多线程ping大量服务器在线情况
需要ping一个网段所有机器的在线情况,shell脚步运行时间太长,用python写个多线程ping吧,代码如下:
复制代码
#!/usr/bin/python
#coding=utf-8
'''
Created on 2015-8-4
@author: Administrator
'''
import threading,subprocess
from time import ctime,sleep,time
import Queue
queue=Queue.Queue()
class ThreadUrl(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
while True:
host=self.queue.get()
ret=subprocess.call('ping -c 1 -w 1 '+host,shell=True,stdout=open('/dev/null','w'))
if ret:
print "%s is down" % host
需要ping一个网段所有机器的在线情况,shell脚步运行时间太长,用python写个多线程ping吧,代码如下:
复制代码
#!/usr/bin/python
#coding=utf-8
'''
Created on 2015-8-4
@author: Administrator
'''
import threading,subprocess
from time import ctime,sleep,time
import Queue
queue=Queue.Queue()
class ThreadUrl(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
while True:
host=self.queue.get()
ret=subprocess.call('ping -c 1 -w 1 '+host,shell=True,stdout=open('/dev/null','w'))
if ret:
print "%s is down" % host
资源评论
蜀道难123
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功