×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

For host in range - basic question!

For host in range - basic question!

For host in range - basic question!

(OP)
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

RE: For host in range - basic question!

CODE

pinglist = []

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

RE: For host in range - basic question!

(OP)
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()
----------------------------------------------------

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close