Internet: Fix whois of domains whose whois server is too lazy to close a connection.

This commit is contained in:
Valentin Lorentz 2013-01-05 18:46:56 +01:00
parent 10197b9956
commit db48d78050

View File

@ -28,6 +28,7 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
### ###
import time
import socket import socket
import telnetlib import telnetlib
@ -79,15 +80,24 @@ class Internet(callbacks.Plugin):
irc.errorInvalid(_('domain')) irc.errorInvalid(_('domain'))
return return
try: try:
t = telnetlib.Telnet('%s.whois-servers.net' % usertld, 43) sock = utils.net.getSocket('%s.whois-servers.net' % usertld)
sock.connect(('%s.whois-servers.net' % usertld, 43))
except socket.error, e: except socket.error, e:
irc.error(str(e)) irc.error(str(e))
return return
sock.settimeout(5)
if usertld == 'com': if usertld == 'com':
t.write('=') sock.send('=')
t.write(domain.encode('ascii')) sock.send(domain.encode('ascii'))
t.write(b'\r\n') sock.send(b'\r\n')
s = t.read_all()
s = ''
end_time = time.time() + 5
try:
while end_time>time.time():
s += sock.recv(4096)
except socket.error:
pass
server = registrar = updated = created = expires = status = '' server = registrar = updated = created = expires = status = ''
for line in s.splitlines(): for line in s.splitlines():
line = line.decode('ascii').strip() line = line.decode('ascii').strip()