A
ADE
Hi everyone:
I was just wondering if this code makes sense to anyone. And if I am
writing it correctly, the program seems to keep crashing. I was also
wondering if anyone had any pointers.
The program is supposed to randomly choose an ip address and try and make a
conection on port 80
Cheers to anyone who helps
# GENERATE AND TRY AND CONNECT TO RANDOM IP ADDRESS
import socket, struct, random
RAND = random.random()
PORT = 80
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# These two functions aren't mine
def dottedQuadToNum(ip):
"convert decimal dotted quad string to long integer"
return struct.unpack('L',socket.inet_aton(ip))[0]
def numToDottedQuad(n):
"convert long int to dotted quad string"
return socket.inet_ntoa(struct.pack('L',n))
# I Think I understand them
HOST = dottedQuadToNum("24.207.19.240")
RAND = random.randrange(HOST)
HOST = numToDottedQuad(RAND)
try:
sock.connect((HOST, PORT))
print "connected to " + HOST + " on",
print PORT
sock.close()
except:
print "could not connect to " + HOST + " on",
print PORT
Cheers
Thank You
Andrew
I was just wondering if this code makes sense to anyone. And if I am
writing it correctly, the program seems to keep crashing. I was also
wondering if anyone had any pointers.
The program is supposed to randomly choose an ip address and try and make a
conection on port 80
Cheers to anyone who helps
# GENERATE AND TRY AND CONNECT TO RANDOM IP ADDRESS
import socket, struct, random
RAND = random.random()
PORT = 80
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# These two functions aren't mine
def dottedQuadToNum(ip):
"convert decimal dotted quad string to long integer"
return struct.unpack('L',socket.inet_aton(ip))[0]
def numToDottedQuad(n):
"convert long int to dotted quad string"
return socket.inet_ntoa(struct.pack('L',n))
# I Think I understand them
HOST = dottedQuadToNum("24.207.19.240")
RAND = random.randrange(HOST)
HOST = numToDottedQuad(RAND)
try:
sock.connect((HOST, PORT))
print "connected to " + HOST + " on",
print PORT
sock.close()
except:
print "could not connect to " + HOST + " on",
print PORT
Cheers
Thank You
Andrew