欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python3实现域名查询和whois查询功能

时间:2021-05-07 10:48:29|栏目:Python代码|点击:

1. 域名查询

万网提供了域名查询接口,接口采用HTTP协议:

接口URL:http://panda.www.net.cn/cgi-bin/check.cgi

接口参数:area_domain,接口参数值为标准域名,例:doucube.com

调用举例:

http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=doucube.com

返回:

<?xml version="1.0" encoding="gb2312" ?> 
- <property>
 <returncode>200</returncode> 
 <key>doucube.com</key> 
 <original>211 : Domain name is not available</original> 
 </property>

返回结果说明:

<returncode>200</returncode> 返回码,200表示返回成功
<key>doucube.com</key> 表示当前查询的域名
<original>211 : Domain name is not available</original> 返回结果的原始信息,主要有以下几种

original=210 : Domain name is available  表示域名可以注册
original=211 : Domain name is not available 表示域名已经注册
original=212 : Domain name is invalid  表示查询的域名无效
original=213 : Time out 查询超时

用python3实现如下

1.1 查询已经被注册的域名

import urllib.request
req = urllib.request.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=doucube.com')
print(req.read().decode())

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

<?xml version="1.0" encoding="gb2312" ?> 
- <property>
 <returncode>200</returncode> 
 <key>doucube.com</key> 
 <original>211 : Domain name is not available</original> 
 </property>

1.2 查询没有被注册的域名

req2 = urllib.request.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=doucube.net')
print(req2.read().decode())

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

 <?xml version="1.0" encoding="gb2312" ?> 
- <property>
 <returncode>200</returncode> 
 <key>doucube.net</key> 
 <original>210 : Domain name is available</original> 
 </property>

1.3 查询不存在的域名,使用不存在的后缀

req3 = urllib.request.urlopen('http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=doucube.net2')
print(req3.read().decode())

返回结果:域名无效

 <?xml version="1.0" encoding="gb2312" ?> 
- <property>
 <returncode>200</returncode> 
 <key>doucube.net2</key> 
 <original>212 : Domain name is invalid</original> 
 </property>

.whois查询

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

req_whois = urllib.request.urlopen('http://whois.chinaz.com/doucube.com')
print(req_whois.read().decode())

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

<div style=" text-align:center;"> 
 <div class="div_whois">
  域名:doucube.com&nbsp;&nbsp;
  <a href='http://www.doucube.com' target=_blank>访问此网站</a></div>
 <div id="whoisinfo" class="div_whois">
  注册商:GODADDY.COM, LLC<br/>
  域名服务器:whois.godaddy.com<br/>
  DNS服务器:DNS1.FREEHOSTIA.COM<br/>
  DNS服务器:DNS2.FREEHOSTIA.COM<br/>
  域名状态:运营商设置了客户禁止删除保护<br/>
  域名状态:运营商设置了客户禁止续费保护<br/>
  域名状态:运营商设置了客户禁止转移保护<br/>
  域名状态:运营商设置了客户禁止修改保护<br/>
  更新时间:2012年05月28日<br/>
  创建时间:2012年05月23日<br/>
  过期时间:2013年05月23日<br/>
  联系人:zhu, alice<br/>
  联系方式:<img src="/displayemail.aspx?email=M8N8oc1O|iQhqGCDHdpH9m77v2qrQfW8"/>
  <br/>
  <br/>
 </div>
</div>

上一篇:关于python导入模块import与常见的模块详解

栏    目:Python代码

下一篇:简述Python中的面向对象编程的概念

本文标题:python3实现域名查询和whois查询功能

本文地址:http://www.codeinn.net/misctech/116441.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有