Python 官方文档:入门教程 => 点击学习
####################################################""" 实现多线程ping一个网段的地址,测试联通性 copyright 2016/9/30 lighter_py"""#######
####################################################
"""
copyright 2016/9/30 lighter_py
"""
####################################################
import os
import queue
import threading
class Pinger(threading.Thread):
def __init__(self,queue,pingIp,pinGCoint=1):
threading.Thread.__init__(self)
self.queue = queue
self.pingIp = pingIp
self.pingCount = 1
def run(self):
pingResult = os.popen('ping -n' + ' ' + str(self.pingCount) + ' ' +self.pingIp).read()
if '无法访问目标主机' not in pingResult:
print(self.pingIp,'\t is online')
self.queue.get()
class creatpinger:
def __init__(self,queue,pingIpParagraph,allcount=255,pingCount=1):
self.queue = queue
self.pingIpParagraph = pingIpParagraph
self.allcount = allcount
self.pingCount = 1
self.create()
def create(self):
for i in range(1,self.allcount+1):
self.queue.put( i )
Pinger(self.queue,self.pingIpParagraph+str(i),self.pingCount).start()
if __name__ == '__main__':
creatpinger(queue.Queue(100),'192.168.1.')
--结束END--
本文标题: python3实现多线程ping一个网段
本文链接: https://www.lsjlt.com/news/192650.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0