####################################################
"""
Implement multi-threaded ping a network segment address, test connectivity
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 ' Cannot access target host ' 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. ')
Python3 implementing multi-threaded ping a network segment