Make whois queries

PyWhois is a python module for retrieving WHOIS information of domains.

Script:

#!/usr/bin/python
 
import sys, whois
from optparse import OptionParser
 
def main():	
	try:
		parser = OptionParser()
		parser.add_option("-d", "--domain", dest="domain", help="domain to query")
		(options, args) = parser.parse_args()
 
		if options.domain==None:
			parser.print_help()
			sys.exit(0)
 
		print 'looking for ' + options.domain + '..n'
		w = whois.whois(options.domain)
 
		if w.domain_name:
			if isinstance(w.domain_name, list):
				for domain_name in w.domain_name:
					print 'Domain Name:' + domain_name
			else:
				print 'Domain Name:' + w.domain_name
		else:
			print 'Domain Name:-'
 
		if w.registrar:
			if isinstance(w.registrar, list):
				for registrar in w.registrar:
					print 'Registrar:' + registrar
			else:
				print 'Registrar:' + w.registrar
		else:
			print 'Registrar:-'
 
		if w.whois_server:
			if isinstance(w.whois_server, list):
				for whois_server in w.whois_server:
					print 'Whois Server:' + whois_server
			else:
				print 'Whois Server:' + w.whois_server
		else:
			print 'Whois Server:-'
 
		if w.referral_url:
			if isinstance(w.referral_url, list):
				for referral_url in w.referral_url:
					print 'Referral URL:' + referral_url
			else:
				print 'Referral URL:' + w.referral_url
		else:
			print 'Referral URL:-'
 
		if w.name_servers:
			if isinstance(w.name_servers, list):
				for name_server in w.name_servers:
					print 'Name Server:' + name_server
			else:
				print 'Name Server:' + w.name_servers
		else:
			print 'Name Server:-'
 
		if w.status:
			if isinstance(w.status, list):
				for status in w.status:
					print 'Status:' + status
			else:
				print 'Status:' + w.status
		else:
			print 'Status:-'
 
		if w.updated_date:
			if isinstance(w.updated_date, list):
				for updated_date in w.updated_date:
					print 'Updated Date:' + str(updated_date)
			else:
				print 'Updated Date:' + str(w.updated_date)
		else:
			print 'Updated Date:-'
 
		if w.creation_date:
			if isinstance(w.creation_date, list):
				for creation_date in w.creation_date:
					print 'Creation Date:' + str(creation_date)
			else:
				print 'Creation Date:' + str(w.creation_date)
		else:
			print 'Creation Date:-'
 
		if w.expiration_date:
			if isinstance(w.expiration_date, list):
				for expiration_date in w.expiration_date:
					print 'Expiration Date:' + str(expiration_date)
			else:
				print 'Expiration Date:' + str(w.expiration_date)
		else:
			print 'Expiration Date:-'
 
		if w.emails:
			if isinstance(w.emails, list):
				for email in w.emails:
					print 'Email:' + email
			else:
				print 'Email:' + w.emails
		else:
			print 'Email:-'
	except Exception as e:
		print "%s" % e
 
if __name__ == "__main__":
    main()

Usage:

python mywhois.py -d domain_name.com
Categories: Network, Python Tags: , ,
%d bloggers like this: