利用Python实现域名查询和whois查询

一、域名查询

万网提供了域名查询接口,接口采用HTTP协议: 接口URL:http://panda.www.net.cn/cgi-bin/check.cgi 接口参数:area_domain,接口参数值为标准域名,例:52bong.com 调用举例:
http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bong.com
返回:


200
52bong.com
211 : Domain exists
返回结果说明:
200 返回码,200表示返回成功
52bong.com  表示当前查询的域名
211 : Domain exists 返回结果的原始信息,主要有以下几种
 
original=210 : Domain name is available     表示域名可以注册
original=211 : Domain exists    表示域名已经注册
original=212 : Domain name is invalid       表示查询的域名无效
original=213 : Time out 查询超时

Python实现

1.1 查询已经被注册的域名
>>> import urllib2
[quote]>> req=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bong.com')
>>> print (req.read().decode())
返回结果:不可用,已经被注册 [attach]563[/attach] 1.2 查询没有被注册的域名
>>> req2=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bongxxx.com')
>>> print (req2.read().decode())
返回结果:可用,未被注册 [attach]564[/attach] 1.3 查询不加后缀的域名
>>> req3=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bong')
>>> print (req3.read().decode())
返回结果:超时 [attach]565[/attach]

二、whois查询

由于没有找到像域名查询接口那样好的API,这里直接抓取站长之家的whois查询页面(http://whois.chinaz.com/)
>>> whois = urllib2.urlopen('http://whois.chinaz.com/qclouds.com.cn')
>>> print (whois.read().decode())
在返回的结果中有这样一段html代码,这段信息就是查询的whois信息 [attach]566[/attach][/quote]

0 个评论

要回复文章请先登录注册