如果PyDNS库,跳过本地名称服务器,直接向权威名称服务器查询。如baidu.com查询.com域名服务器,并从各个域名服务器中查询下一即域名,并输出相关信息。

#! /usr/bin/env python
# Expanded DNS library example - Chapter 4 - DNSany.py import sys, DNS def hierquery(qstring, qtype):
"""Given a query type qtype, returns answers of that type for lookup
qstring. If no answers are found, removes the most specific component
(the part before the leftmost period) and retries the query with the result.
If the topmost query fails, returns None. """
reqobj = DNS.Request()
try:
answerobj = reqobj.req(name=qstring, qtype=qtype)
answers = [x['data'] for x in answerobj.answers if x['type']==qtype]
except DNS.Base.DNSError:
answers = []
if len(answers):
return answers
else:
remainder = qstring.split(".", 1);
if len(remainder) == 1:
return None
else:
return hierquery(remainder[1], qtype) def findnameservers(hostname):
"""Attempts to determine the authoritative nameservers for a given
hostname, Returns None on failure. """
return hierquery(hostname, DNS.Type.NS) def getrecordsfromnameserver(qstring, qtype, nslist):
"""Given a list of nameservers in nslist, executes the query requested
by qstring and qtype on each in order, returning the data from the
first server that returned 1 or more answers. If no server returned
any answers, return []. """
for ns in nslist:
reqobj = DNS.Request(server = ns)
try:
answers = reqobj.req(name=qstring, qtype=qtype).answers
if len(answers):
return answers
except DNS.Base.DNSError:
pass
return [] def nslookup(qstring, qtype, verbose = -1):
nslist = findnameservers(qstring)
if nslist is None:
raise RuntimeError, "Could not find nameserver to use."
if verbose:
print "Using nameservers:", ", ".join(nslist)
return getrecordsfromnameserver(qstring, qtype, nslist) if __name__ == "__main__":
query = sys.argv[1]
DNS.DiscoverNameServers() answers = nslookup(query, DNS.Type.ANY)
if not len(answers):
print "Not found."
for item in answers:
print "%-5s %s" % (item['typename'], item['data'])

运行结果如图所示:

【Python Network】权威域名服务器级联查询的更多相关文章

  1. 【Python Network】分解DNS查询结果

    针对DNS查询records,通过NS.PTR.CNAME和MX类别不同,返回数据将包含另外主机名.为了解最终的IP地址,通过将返回信息分解.继续使用PyDNS获取详细信息. #! /usr/bin/ ...

  2. DNS(一)之禁用权威域名服务器递归解析

    DNS dns是互联网中最核心的带层级的分布式系统,负责把域名解析成ip,把IP解析出域名,以及宣告邮件路由信息等等,使得使用域名访问网站,收发邮件成了可能. bind(berkeley Intern ...

  3. Oracle级联查询

    在ORACLE 数据库中有一种方法可以实现级联查询   select  *                //要查询的字段 from table              //具有子接点ID与父接点I ...

  4. Mybatis 级联查询 (一对多 )

    后台系统中 涉及到添加试卷 问题 答案的一个模块的.我需要通过试卷 查询出所有的试题,以及试题的答案.这个主要要使用到Mybatis的级联查询. 通过试卷 查询出与该试卷相关的试题(一对多),查询出试 ...

  5. python network programming tutorial

    关于网络编程以及socket 等一些概念和函数介绍就不再重复了,这里示例性用python 编写客户端和服务器端. 一.最简单的客户端流程: 1. Create a socket 2. Connect ...

  6. Mybatis 之级联查询 一对多配置

    Mybatis级联 查询相对于hibenate是有点麻烦,但是相应好处也是有的,Mybatis轻量.根据自己要的字段配置方便 一对多配置用   <collection property=&quo ...

  7. 三级级联查询省份名称和编码(保证名称不重复)的SQL语句

    三级级联查询省份名称和编码(保证名称不重复)的SQL语句 1.省份.地市和县级数据库表 2.SQL语句 SELECT DISTINCT t.`province_name`,t.`province_co ...

  8. oracle使用connect by进行级联查询 树型菜单

    Oracle使用connect by进行级联查询 树型菜单(转) connect by可以用于级联查询,常用于对具有树状结构的记录查询某一节点的所有子孙节点或所有祖辈节点. 来看一个示例,现假设我们拥 ...

  9. 使用cglib实现数据库框架的级联查询

    写在前面的 这一章是之前写的<手把手教你写一个Java的orm框架> 的追加内容.因为之前写的数据库框架不支持级联查询这个操作,对于有关联关系的表用起来还是比较麻烦,于是就准备把这个功能给 ...

随机推荐

  1. RDLC打印或导出Word的 分页设置 页边距和页面大小

    RDLC 导出Word的时候发现,Word的尺寸和页边距有问题,查了MSDN看到这样一段话 Page Sizing When the report is rendered, the Word page ...

  2. [04] SQL语句优化之索引

    1.索引的概念 根据书的目录可以知道内容所在的页码,不用一页一页翻书,可直接通过页码找到内容.数据库的索引类似于书本的目录,索引指向内容存储位置,可直接定位到内容而不必扫描整张表,减少了磁盘的I/O次 ...

  3. iOS NSMutableArray替换某个元素

    A * a1 = [A new]; A * a2 = [A new]; A * a3 = [A new]; A * a4 = [A new]; NSMutableArray *arr = [[NSMu ...

  4. JavaScript中的apply与call与arguments对象

    (一) call方法 语法:presentObj.call(thisObj,arg1,arg2,arg3...) 参数thisObj :将被用作当前对象presentObj的对象. 当thisObj无 ...

  5. 包含为 HTTP 定义的状态代码的值(枚举)

    using System; namespace System.Net { // 摘要: // 包含为 HTTP 定义的状态代码的值. public enum HttpStatusCode { // 摘 ...

  6. win/linux 下使用 psutil 获取进程 CPU / memory / IO 占用信息

    psutil - A cross-platform process and system utilities module for Python 1. 安装 pip 安装即可. windows 下需要 ...

  7. [java学习笔记]JDK的安装和环境变量的配置

    1.JDK的下载和安装 jdk(java development kit)是java提供给我们的一套java开发工具,它必运行在JVM(java虚拟机)上,java语言的跨平台性就是利用java运行在 ...

  8. the evaluation period for visual studio trial edition has ended的解决方法-转发

    首先献上自己收集的Visual studio 2008序列号: Visual Studio 2008 Professional Edition: XMQ2Y-4T3V6-XJ48Y-D3K2V-6C4 ...

  9. Linux中的sed

    sed [选项] [动作] 文件 选项:     -n :静默模式.使用-n则只有经过sed处理的那一行.     -e :允许多重编辑:       -f :结果默认输出到终端,使用-f会将结果写在 ...

  10. Linux简介及Ubuntu安装

    Linux简介及Ubuntu安装 常见指令 系统管理命令 打包压缩相关命令 关机/重启机器 Linux管道 Linux软件包管理 vim使用 用户及用户组管理 文件权限管理 大牛笔记-www.weix ...