Python3 implementing multi-threaded ping a network segment

Source: Internet
Author: User

####################################################

"""

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.