Hi Kmarris tks for your reply,
hmmm! I already used this one but this is not exactly what I want. Let me explain. I have below script(no.1) that validates IP, put it in a list and display the list of my 5 IPs. but I want to put all my IPs to be ping using script no2 (see below). But I have a hard time to match script no 1 to script no 2, I must change the 2 command line in script no2 see:
for host in range(60,70):
ip = "192.168.200."+str(host)
but I don't know what to type exactly, I did look into 360 pages of tutorial but unsucessful. Pls can you help me ?
script no 1:
------------------------------------
import os
import re
def validIP(ipAddress):
ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$"
re_ip = re.compile(ipRegex)
return re_ip.match(ipAddress)
def read_ip(N):
valid_ip = []
i = 1
while (i<=N):
ipAddress = raw_input("Donnez l'adresse IP d'Origine n°%d: " % i)
if validIP(ipAddress):
valid_ip.append(ipAddress)
i += 1
else:
print "adresse IP invalide. recommencez"
return valid_ip
# 1 est le nombre d'IP à lire
ip_list = read_ip(5)
print ip_list
------------------------------------------------------
script no 2
------------------------------------------------------
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")
# This code is what each parallel thread does
# the 'run' method is triggered when 'start' is called
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 = ("No response","Partial Response","Alive")
print time.ctime()
pinglist = []
for host in range(60,70):
ip = "192.168.200."+str(host)
# create a thread, add it to a thread list
current = testit(ip)
pinglist.append(current)
# start the thread running
current.start()
for pingle in pinglist:
# await the completion of each thread in turn
pingle.join()
print "Status from ",pingle.ip,"is",report[pingle.status]
print time.ctime()
----------------------------------------------------