Query domain name whois info by Python

In one of our former post, we give an example on how to query IP whois info by Python, here is an example on how to query whois information for a domain name.

#encoding = utf8

import sys
import socket

PORT  =  43
WhoisServers = {'com':'whois.internic.net',

fulldomain = sys.argv[1]

if fulldomain.startswith('www.'):
    fulldomain = fulldomain[4:]

domain = fulldomain[-3:]
print 'Domain: ',fulldomain  
if not WhoisServers.get(domain):
    whoisserver = WhoisServers['DEF']
    whoisserver = WhoisServers[domain]
print whoisserver

    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.send(fulldomain + "\r\n")
    response = ''

    while True:
        data = s.recv(4096)
        response += data
        if data == '':
    infomation = response.lower()
        pos = infomation.find('expiration date: ')
        expirDate = infomation[pos+17:pos+28]
        print 'Expiration Date:',expirDate
        print 'unkown'

    print 'time out'

Looks smart! But never mind that the whois info cannot be returned correctly sometimes. We also have a online whois query script here, which is created by PHP.

The script is copied from here: http://blog.hysia.com/

Share this post

6 thoughts on “Query domain name whois info by Python

  1. I’d have to examine with you here. Which isn’t something I often do! I get pleasure from studying a put up that may make folks think. Also, thanks for permitting me to comment!

  2. Everything is very open with a very clear clarification of the
    issues. It was really informative. Your website is
    useful. Thank you for sharing!

  3. I have noticed you don’t monetize your site, don’t waste your traffic,
    you can earn extra bucks every month because you’ve got high quality content.
    If you want to know how to make extra money, search for: Boorfe’s tips best adsense alternative

Post Comment