Am I on the right path

matt okeson-harlow mharlow-dated-1093786836.bbea92 at grephead.com
Thu Aug 26 10:11:58 EDT 2004


On 2004-08-25, Batista, Facundo <FBatista at uniFON.com.ar> wrote:
> [ADE]
>
> #- The program is supposed to randomly choose an ip address and 
> #- try and make a
> #- conection on port 80
>
> You can generate random IP like this, also:
>
>>>> import random
>>>> '.'.join([str(random.randint(0,255)) for x in range(4)])
> '168.240.211.252'

[snip]

to keep from duplicating ips...

import random

def newip():
    ip = '.'.join([str(random.randint(0,255)) for x in range(4)])
    return ip

oldip = {}

for i in range(10):
    ip = newip()
    if not oldip.has_key(ip):
        print ip
        oldip[ip] = 1



-- 
matt okeson-harlow
http://technomage.net



More information about the Python-list mailing list