Collecting IP range

Discussion in 'Python' started by yawgmoth7, Jan 31, 2006.

  1. yawgmoth7

    yawgmoth7 Guest

    Hello, I'm sure that this has been discussed before, but I have a
    question. I have written a few port scanners, banner grabbers in the
    past and have never found a good way to get a range of IP's.
    Obviously, in my opinion the best and simplest way to do somethign
    like and simple port scanner is to do something like:

    <code>
    for ips in range(startip,endip):
    <do blah>

    Well, since range() won't take a normal IP(Such as 127.0.0.1). and,
    you can't take it as 127001(Since socket.connect() won't take that).
    What would you suggest as a better way to approach this?

    Thanks for all your help.
    ----------------------------
    gurusnetwork.org
    Gurus'Network - Are you a guru?

    http://www.12dailypro.com/?ref=288444
     
    yawgmoth7, Jan 31, 2006
    #1
    1. Advertising

  2. yawgmoth7 schrieb:
    > Hello, I'm sure that this has been discussed before, but I have a
    > question. I have written a few port scanners, banner grabbers in the
    > past and have never found a good way to get a range of IP's.
    > Obviously, in my opinion the best and simplest way to do somethign
    > like and simple port scanner is to do something like:
    >
    > <code>
    > for ips in range(startip,endip):
    > <do blah>
    >


    you might want to take a look at IPy:

    http://c0re.23.nu/c0de/IPy/

    iterating over ip-address ranges is very easy there:

    >>> ip = IP('127.0.0.0/30')
    >>> for x in ip:

    ... print x
    ...
    127.0.0.0
    127.0.0.1
    127.0.0.2
    127.0.0.3

    --
    David.
     
    David Murmann, Jan 31, 2006
    #2
    1. Advertising

  3. yawgmoth7 schrieb:
    > Well, I seem to have a bit of a problem:
    > >>>import IPy
    > >>>ip =IP('127.0.0.1/30')

    > Traceback (Most recent call last):
    > File "<stdin>". line `, in ?
    > NameError: name 'IP' is not defined
    > >>>


    to make this work with "import IPy" you need
    to use "ip = IPy.IP('127.0.0.1/30')".

    > I've tried doing it like:
    > from IPy import *
    > And then doing that, but it gives mea different error. Thanks once again
    >


    what error are you getting? it works for me...

    --
    David.
     
    David Murmann, Jan 31, 2006
    #3
  4. Heiko Wundram, Jan 31, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    46
    Views:
    992
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    420
    James Kanze
    Jul 16, 2008
  3. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    162
    Tomoyuki Kosimizu
    Nov 27, 2003
  4. David Bird
    Replies:
    1
    Views:
    229
    Tiago Macedo
    Jun 23, 2008
  5. Joey Zhou
    Replies:
    5
    Views:
    243
    Joey Zhou
    Apr 15, 2011
Loading...

Share This Page