Quantcast
Channel: BinaryTides » Python
Viewing all articles
Browse latest Browse all 10

Python program to fetch domain whois data using sockets

$
0
0
Whois
The whois information of a domain name provides various details like registrar, owner, registration date, expiry date etc. The whois information is provided by the corresponding whois servers of the registrars. The first step is to contact whois.iana.org which provides the actual whois server of a domain name. Next the particular whois server is contacted which provides the full whois data of the domain.
Implementation is quite simple and python makes it even simpler.

#!/usr/bin/python

'''
Program to fetch whois information of a domain name
Silver Moon
m00n.silv3r@gmail.com
'''
import socket, sys

#Perform a generic whois query to a server and get the reply
def perform_whois(server , query) :
#socket connection
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.connect((server , 43))

#send data
s.send(query + '\r\n')

#receive reply
msg = ''
while len(msg) < 10000:
chunk = s.recv(100)
if(chunk == ''):
break
msg = msg + chunk

return msg
#End

#Function to perform the whois on a domain name
def get_whois_data(domain):

#remove http and www
domain = domain.replace('http://','')
domain = domain.replace('www.','')

#get the extension , .com , .org , .edu
ext = domain

#If top level domain .com .org .net
if(ext == 'com' or ext == 'org' or ext == 'net'):
whois = 'whois.internic.net'
msg = perform_whois(whois , domain)

#Now scan the reply for the whois server
lines = msg.splitlines()
for line in lines:
if ':' in line:
words = line.split(':')
if 'Whois' in words and 'whois.' in words:
whois = words.strip()
break;

#Or Country...

Read full post here
Python program to fetch domain whois data using sockets


Viewing all articles
Browse latest Browse all 10

Trending Articles