whois

Chunk Light Fluffy meowing at banet.net
Sun Mar 5 00:50:57 EST 2000


Gregoire Welraeds wrote:
> Is there any module that implement all of part of the whois tool ?

Whois clients are very simple minded.  All the real work is done by the
server, so all you really have to do is open the socket, send a one
line query, then read the response until the server closes the socket.

If you want something smarter, or even just a decent list of all the
whois servers, try <URL:http://www.geektools.com/software.html>


import socket, string

WHOIS_PORT = 43
CRLF = "\015\012"

def whois(host, query):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(host, WHOIS_PORT)
    f = s.makefile('rb')
    s.send(query + CRLF)
    rv = []
    while 1:
        line = f.readline()
        if not line:
            break
        if line[-2:] == CRLF:
            line = line[:-2]
        elif line[-1:] in CRLF:
            line = line[:-1]
        rv.append(line)
    f.close()
    s.close()
    return string.join(rv, "\n") + "\n"

print whois("whois.networksolutions.com", "internic.net")



More information about the Python-list mailing list