trying to WHOIS a site within IRC
if data.find('!whois') != -1:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("com.whois-servers.net", 43))
s.send('www.msn.com' + "\r\n")
response = ''
while True:
d = s.recv(4096)
response += d
if d == '':
开发者_Go百科 break
s.send('PRIVMSG ' + chan + " " + response + '\r\n')
s.close()
when I type !whois on the channel, it doesnt do anything, I'm probably doing this wrong. Any help will be appreciate it. Thanks.
Note: There's another socket already connected.
This snippet works in python3.1 with the whois site you mentioned.
#!/usr/bin/env python3
import socket
domain = "msn"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("com.whois-servers.net", 43))
s.send(("%s\r\n" % domain).encode())
response = ""
while True:
r = s.recv(4096).decode()
response += r
if r == "":
break
print(response)
精彩评论