I'm not sure what happened to this code. I keep getting this socket.gaierror error; \.
import sys
import socket
import random
filename = "whoiservers.txt"
server_name = random.choice(list(open(filename)))
print "connecting to %s..." % server_name
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server_name, 43))
s.send(sys.argv[1] + "\r\n")
response = ''
while True:
d = s.recv(4096)
response += d
if d == '':
break
s.close()
print
print response
s.connect((server_name, 43))
File "<string>", line 1, in connect
socket.gaierror: [Errno 11001] getaddrinfo failed
Update:
After adding, server_name = random.choice(list(open(filename)))[:-1]I no longer receive this .gaierror socket, but I get:
socket.error: [Errno 10060] The connection attempt failed because the connected pa rty did not respond properly after a certain period of time or made a connection f because the connected host was unable to respond
Mike
source
share