Python: Random IP

I’m not very experienced with python, but I occasionally program with some help from a friend. This script generates random ip addresses and tries to connect to them, displaying the addresses that work:

import socket
from random import randint

def randip():
    while True:
        yield ".".join(str(randint(1, 255)) for i in range(4))

a = []
for address in randip():
                s = socket.socket()
                s.connect((address, 80))
                print address, "WORKS!!!"
        except socket.error:
                if len(a) != 5:
                        print a
                        raw_input("press enter")


2 Responses to “Python: Random IP”

  1. 1 Mike November 12, 2009 at 2:50 am

    Hi there. I am looking for a way to do exactly what you describe above…generate IP addresses randomly. However, I am not programmer so I don’t know exactly how to employ your script. Can you give me some more details on where and how to use it please? Thank you.

  2. 2 morphex November 13, 2009 at 10:17 pm

    You should become more familiar with python, for example by googling you can find lots of guides and docs. You could compile this to be run as a windows executable. What exactly do you want to do?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


Write comments if you have something you need to ask.

Current OS:

Arch Linux / Windows 7

%d bloggers like this: