#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    3
    Rep Power
    0

    Talking Increment IP an adress?


    hi folks,

    how can i increment an ip adress in a speacial range? when start ip and stop ip is given ?

    with best regards

    chill4
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    Something like this perhaps?
    Code:
    #!/usr/bin/env python                  
    
    base_ip = "192.168.1"
    start_oct = raw_input("Enter your start IP octet: ")
    end_oct = raw_input("Enter your end IP octet: ")
    for octet in xrange(int(start_oct), int(end_oct) + 1):
        ip = base_ip + "." + str(octet)
        print ip
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Yet another way to do this ,

    Code:
    #!/usr/bin/env python
    
    def incrementAddress(address, to = 249, by = 1):
        position = address.rindex('.') + 1
        for each in xrange(1, to + 1, by):
            yield address[:position] + str(each)
    
    if __name__ == '__main__':
        for IP in incrementAddress('123.123.123.1', 5):
            print IP
    Have fun,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo