好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python3实现域名查询和whois查询

python3实现域名查询和whois查询

关键字: python3   域名查询   域名查询接口   whois查询
原文: http://www.cnblogs.com/txw1958/archive/2012/08/31/python3-domain-whois.html  

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>

2.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  > 

文档信息: ■ 版权声明:自由转载-非商用-非衍生-保持署名 ■ 原文网址:http://txw1958.cnblogs.com/

分类:  Python3

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于python3实现域名查询和whois查询的详细内容...

  阅读:36次