文档章节

Python program to fetch domain whois data using...

Yisen
 Yisen
发布于 2012/10/25 14:28
字数 380
阅读 51
收藏 0

转自 http://www.binarytides.com/python-program-to-fetch-domain-whois-data-using-sockets/

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[-3:]
	
	#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[0] and 'whois.' in words[1]:
					whois = words[1].strip()
					break;
	
	#Or Country level - contact whois.iana.org to find the whois server of a particular TLD
	else:
		#Break again like , co.uk to uk
		ext = domain.split('.')[-1]
		
		#This will tell the whois server for the particular country
		whois = 'whois.iana.org'
		msg = perform_whois(whois , ext)
		
		#Now search the reply for a whois server
		lines = msg.splitlines()
		for line in lines:
			if ':' in line:
				words = line.split(':')
				if 'whois.' in words[1] and 'Whois Server (port 43)' in words[0]:
					whois = words[1].strip()
					break;
	
	#Now contact the final whois server
	msg = perform_whois(whois , domain)
	
	#Return the reply
	return msg
# end
        
# get the domain name from command line argument
domain_name = sys.argv[1]
print get_whois_data(domain_name)

Run the program by issuing the following command at the terminal.

$ python whois.py stackoverflow.com

The commandline argument should contain the domain name. The output would be the whois data.

© 著作权归作者所有

Yisen

Yisen

粉丝 169
博文 61
码字总数 41339
作品 0
深圳
产品经理
私信 提问
Python使用Whois协议查询域名、IP地址信息

原文地址:http://shajunxing.tpddns.cn:8888/web/blog/2018-04-17-Python使用Whois协议查询域名、IP地址信息/index.html 问题由来 我想查询某个IP地址所属的运营商,于是在百度里搜索,得到...

shajunxing
2018/04/17
0
0
验证域名是否为该用户的域名

主要是验证域名的注册人邮箱是否在用户验证过邮箱中。 用到第三方接口。 会有点慢,加一个 进行中。。。加载图。 前台代码: function verifyDomain(val){ var ajaxurl = APPROOT+"/index.ph...

技术小胖子
2017/11/08
0
0
Comprehensive Introduction to Apache Spark

Introduction Industry estimates that we are creating more than 2.5 Quintillion bytes of data every year. Think of it for a moment – 1 Qunitillion = 1 Million Billion! Can you i......

grasp_D
2018/06/15
0
0
BackTrack5 whois

whois 用了查询域名注册信息 查询的时候 就不要加上 www 等等了。。。 root@bt :~# whois cctry.com Whois Server Version 2.0 Domain names in the .com and .net domains can now be regi......

sincoder
2012/07/16
0
0
C++ Web Programming

What is CGI ? The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom script. The CGI specs are ......

岭南六少
2011/07/21
0
0

没有更多内容

加载失败,请刷新页面

加载更多

jni接口NewStringUTF崩溃

转载 原文 https://blog.csdn.net/churuxu/article/details/49999575 ndk开发中,将c/c++的UTF8编码的字符串转换成java字符串,使用了NewStringUTF接口。 当字符串中包含emoji字符时,在有些...

shzwork
昨天
3
0
北斗三号IGSO-2卫星发射成功!

6月25日,中国航天科技集团官方公众号宣布,北斗三号IGSO-2卫星发射成功! 航天科技集团表示,6月25日2点09分,我国在西昌卫星发射中心用长征三号乙运载火箭成功将北斗三号第2颗倾斜地球同步...

linuxCool
昨天
3
0
阿里java开发规约的Idea插件安装(英文)

Idea Plugin Prepare Project JDK: 1.7+ Gradle: 3.0+(Require JDK1.8+ for gradle) Build cd p3c-ideagradle clean buildPlugin Run plugin cd p3c-ideagradle runIde# run speci......

Airship
昨天
8
0
很多人转行做程序员选择web前端学习,前端简单在哪里?

不管你是工人阶层还是服务行业,是否想过转行IT,转行IT后肯定会选择一门编程语言进行深入学习,很多转行的人基础都不是太好,不是科班出身,甚至有的是专科乃至中专,前端的HTML和CSS相对其...

智云编程
昨天
2
0
一文读懂内网、公网和NAT

我们做弱电监控系统的时候,都避免不了要跟IP地址打交道,比如摄像头、NVR、服务器等这些设备安装好之后,就需要给它们配上IP,那这个IP地址你了解嘛?今天我们就一起来聊聊什么是内网、公网和...

老孟的Linux私房菜
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部