dnspython

一个Python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验。

安装

pip install dnspython

解析域名为IP

from dns import resolver

f = open('ddd.log', 'w')

with open('urls.txt', 'r') as fp:
for line in fp:
try:
url = line[7:].strip()
ans = resolver.query(url, 'A') # A记录,将主机名转换为IP地址; # for x in ans.response.answer: # 获取结果
# for y in x.items:
# print(y)
t = url + '||Successful!'
except Exception as e:
t = url + '||' + str(e)
print('resolver error!')
finally:
f.write(t + '\n')
f.close()

urls.txt

http://www.lyskjqbyjs.cn
http://www.haict.edu.cn
http://news.kf.cn
http://www.henanjubao.com
http://huixiangtan.smx.net.cn
http://www.hnjnjc.gov.cn
...

ddd.log

www.lyskjqbyjs.cn||Successful!
www.haict.edu.cn||None of DNS query names exist: www.haict.edu.cn., www.haict.edu.cn.
news.kf.cn||Successful!
www.henanjubao.com||Successful!
huixiangtan.smx.net.cn||Successful!
www.xcxnmj.gov.cn||None of DNS query names exist: www.xcxnmj.gov.cn., wx.hazz-l-
www.yhgq.gov.cn||Successful!
www.zzdangshi.com||Successful!
smx.hnwzj.gov.cn||Successful!
wfxy.ayit.edu.cn||Successful!
www.sqsglj.com||All nameservers failed to answer the query www.sqsglj.com. IN A: Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered The DNS operation timed out.; Server 127.0.0.53 UDP port 53 answered SERVFAIL
www.yyxsjj.gov.cn||Successful!
...

socket包的gethostbyname(URL)也能解析IP地址,jd不推荐用socket,推荐dnspython。

dnspython的更多相关文章

  1. CentOS7--DNS处理模块DnsPython的简单使用

    初步了解: DnsPython是Python实现的一个DNS工具包,支持几乎所有的记录类型. 安装: # wget http://www.dnspython.org/kits/1.9.4/dnspyt ...

  2. dnspython模块安装

    wget  http://www.dnspython.org/kits/1.12.0/dnspython-1.12.0.tar.gz tar -zxvf dnspython-1.12.0.tar.gz ...

  3. Python的dnspython库使用指南

    因为平时在测试DNS的时候有些操作手动完成不方便,所以需要用到脚本,而在Python里dnspython这个用于DNS操作的库十分强大,但是无奈网上大部分资料只列举了少部分的用法,所以记录一下我平时使 ...

  4. python自动化运维笔记3 —— dns处理模块dnspython

    1.3 DNS处理模块 dnspython是python实现的一个DNS工具包,它支持几乎所有的记录类型,可以用于查询.传输并动态更新ZONE信息,同时支持TSIG(事物签名)验证消息和EDNS0(扩 ...

  5. DNS处理模块dnspython

    一.介绍 官网:http://www.dnspython.org/ https://pypi.org/project/dnspython/ dnspython是Python的DNS工具包.它支持几乎所 ...

  6. 2.python IP/DNS地址处理之IPy/Dnspython模块

     1.IPy模块 在IP地址规划中,涉及到计算大量的IP地址,包括网段.网络掩码.广播地址.子网数.IP类型等,即便是专业的网络人员也要进行繁琐的计算,而IPy模块提供了专门针对IPV4地址与IPV6 ...

  7. python -- DNS处理模块dnspython

    简介 dnspython – 是python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验 安装dnspython pip install dnspython 使用 常见 ...

  8. python运维开发常用模块(三)DNS处理模块dnspython

    1.dnspython模块介绍: dnspython(http://www.dnspython.org/)是Python实现的一个DNS 工具包,它支持几乎所有的记录类型,可以用于查询.传输并动态更新 ...

  9. DNS 处理模块 dnspython

    简介: dnspython (http://www.dnspython.org/)是Python实现一个DNS的工具包,支持所有的记录类型,可以用于查询.传输并动态更新ZONE信息. 安装 wget ...

随机推荐

  1. UVA1416/LA4080 Warfare And Logistics

    题目大意:有N个点,M条路,如果两条路不连通的话,就将这两条路的距离设置为L 现在要求你求出每两点之间的最短距离和 接着要求 求出炸断 给出的M条路中的一条路后,每两点之间的最短距离和的最大值(翻译来 ...

  2. Leetcode563.Binary Tree Tilt二叉树的坡度

    给定一个二叉树,计算整个树的坡度. 一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值.空结点的的坡度是0. 整个树的坡度就是其所有节点的坡度之和. 示例: 输入: 1 / ...

  3. Effective Modern C++ 条款3:理解decltype

    说起decltype,这是个古灵精怪的东西.对于给定的名字或表达式,decltype能告诉你该名字或表达式的型别.一般来说,它告诉你的结果和你预测的是一样的.不过,偶尔它也会给出某个结果,让你抓耳挠腮 ...

  4. PYTHON__ ITERTOOLS模块

    组成 总体,整体了解 无限迭代器 迭代器 参数 结果 例子 count() start, [step] start, start+step, start+2*step, ... count(10) - ...

  5. stream分组

    1.根据集合元素中的一个属性值分组 Person p1 = new Person("张三", new BigDecimal("10.0"));Person p2 ...

  6. SpringMVC + Mybatis + Shiro + ehcache时缓存管理器报错。

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' ...

  7. 【html、CSS、javascript-13】前端框架Bootstrap

    1.Bootstrap前端框架:包含css样式.js插件.图标等 http://www.bootcss.com/ 2.Font Awesome:非常全的图标大全 https://fontawesome ...

  8. php时间戳转换方式

    {echo date("Y-m-d",$v.created)} 年-月-日 {echo date("Y-m-d H:i:s",$new.created)} 年- ...

  9. PHP实现微信申请退款流程实例源码

    https://www.jb51.net/article/136476.htm 目录 前期准备: 前面讲了怎么实现微信支付,详见博文:PHP实现微信支付(jsapi支付)流程  和ThinkPHP中实 ...

  10. excel2013做数据透视表

    excel2013做数据透视表     Excel最新版更新到2013,相比2003.2007和2010,2013的excel界面方面有一定变化,在操作方面也有一定的便捷性.那么如何使用excel20 ...