Skip to content

Instantly share code, notes, and snippets.

@zeldani
Created February 27, 2014 14:58
Show Gist options
  • Save zeldani/9251707 to your computer and use it in GitHub Desktop.
Save zeldani/9251707 to your computer and use it in GitHub Desktop.
import os
import re
import time
import sys
from threading import Thread
class testit(Thread):
def __init__ (self,ip):
Thread.__init__(self)
self.ip = ip
self.status = -1
def run(self):
pingaling = os.popen("ping -q -c2 "+self.ip,"r")
while 1:
line = pingaling.readline()
if not line: break
igot = re.findall(testit.lifeline,line)
if igot:
self.status = int(igot[0])
testit.lifeline = re.compile(r"(\d) received")
report = ("Sem resposta","Resposta parcial","Ativo")
print time.ctime()
pinglist = []
for host in range(60,70):
ip = "127.0.0."+str(host)
current = testit(ip)
pinglist.append(current)
current.start()
for pingle in pinglist:
pingle.join()
print "Status do ",pingle.ip,"-",report[pingle.status]
print time.ctime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment