×
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

Unrestricted number in a table - Newbies

Unrestricted number in a table - Newbies

Unrestricted number in a table - Newbies

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

RE: Unrestricted number in a table - Newbies

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 or N==0):
        ipAddress = raw_input("Give IP nr%d: " % i)
        if N==0 and ipAddress=="the end":
            break

        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(0)
print ip_list2

Feherke.
http://rootshell.be/~feherke/

RE: Unrestricted number in a table - Newbies

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

RE: Unrestricted number in a table - Newbies

Hi

Quote (Charlie30):

keep going asking me to enter new numbers without ending

Quote (Feherke):

it read until the user enters "the end"

Feherke.
http://rootshell.be/~feherke/

RE: Unrestricted number in a table - Newbies

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

RE: Unrestricted number in a table - Newbies

Hi

Sorry, I did not done such things in Python yet. I am quite new in this area.

Feherke.
http://rootshell.be/~feherke/

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