python实现whois查询_利用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

>>> req=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bong.com')

>>> print (req.read().decode())

返回结果:不可用,已经被注册

0818b9ca8b590ca3270a3433284dd417.png

1.2 查询没有被注册的域名

>>> req2=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bongxxx.com')

>>> print (req2.read().decode())

返回结果:可用,未被注册

0818b9ca8b590ca3270a3433284dd417.png

1.3 查询不加后缀的域名

>>> req3=urllib2.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=52bong')

>>> print (req3.read().decode())

返回结果:超时

0818b9ca8b590ca3270a3433284dd417.png

二、whois查询

由于没有找到像域名查询接口那样好的API,这里直接抓取站长之家的whois查询页面(http://whois.chinaz.com/)

>>> whois = urllib2.urlopen('http://whois.chinaz.com/qclouds.com.cn')

>>> print (whois.read().decode())

在返回的结果中有这样一段html代码,这段信息就是查询的whois信息

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值