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!

Unrestricted number in a table - Newbies

Status
Not open for further replies.

Charlie30

ISP
Aug 1, 2007
6
0
0
CA
I need to entered a undefined number of IP into a list, but below script does only allow me to put 5 configured number IP (see: ip_list = read_ip(5)). What do you sugggest me ?

-----------------------------------------------------------
Code:
def read_ip(N):
    valid_ip = []
    i = 1
    while (i<=N):
        ipAddress = raw_input("Give IP n°%d: " % i)
        if validIP(ipAddress):
            valid_ip.append(ipAddress)
            i += 1
        else:
            print "IP invalid. start again"
    return valid_ip
     
# 5 is the max ip to be read
ip_list = read_ip(5)
print ip_list
-------------------------------------------------------

Tks/Charlie30
 
Hi

I would do like below. If the argument of read_ip() is 0, then it read until the user enters "the end". For any other parameter works like before.
Code:
def read_ip(N):
    valid_ip = []
    i = 1
    while (i<=N [red]or N==0[/red]):
        ipAddress = raw_input("Give IP nr%d: " % i)
        [red]if N==0 and ipAddress=="the end":
            break[/red]
        if validIP(ipAddress):
            valid_ip.append(ipAddress)
            i += 1
        else:
            print "IP invalid. start again"
    return valid_ip

# 5 is the max ip to be read
ip_list = read_ip(5)
print ip_list


# read up to the string "the end"
ip_list2 = read_ip([red]0[/red])
print ip_list2

Feherke.
 
Hello Feherke,

did try your script, but it keep asking me to entered a number and keep going asking me to enter new numbers without ending. Do you have a suggestion ?

 
thanks feherke,

I found the solution, I would like to add a scheduler to one of my script that ping several IPs I would like them to be ping within an interval let say: august 21 at 09:00pm to august 22 to 07:30PM, Do you have any idea how this can be applied to my script...should I use a scheduler function in python ? what do you suggest ?


Brgds/Charlie30
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top