Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For host in range - basic question!

Status
Not open for further replies.

Charlie30

ISP
Aug 1, 2007
6
0
0
CA
Is somebody can assist me ?

I did create a list wish I can validate several IP and than the list is displayed. but I need to know what should I replace on the 2 below command lines to make all IP of the list to be ping? Should I use for host in range command ?
What do you suggest ?



-----------------------------------------------
pinglist = []

for host in range(60,70):
ip = "192.168.200."+str(host)
-----------------------------------------------

Tks/Charlie30
 
Code:
pinglist = []

for host in range(60,70):
   ip = "192.168.200."+str(host)
   pinglist.append(ip)
 
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()
----------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top