dnspython

dnspython

℡╲_俬逩灬. 提交于 2021-02-16 11:38:49
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

Python的dnspython库使用指南

巧了我就是萌 提交于 2021-02-16 11:23:02
  因为平时在测试DNS的时候有些操作手动完成不方便,所以需要用到脚本,而在Python里dnspython这个用于DNS操作的库十分强大,但是无奈网上大部分资料只列举了少部分的用法,所以记录一下我平时使用到的功能,基本上已经能应付大部分的使用场景了。想具体了解dnspython可以登录 官方网站 阅读使用文档. 常用工具 最常用的用法是调用默认的resolver发送解析请求,如 from dns import resolver ans = resolver.query( " www.baidu.com " , " A " ) print ( " qname: " ,ans.qname) print ( " reclass: " ,ans.rdclass) print ( " rdtype: " ,ans.rdtype) print ( " rrset: " ,ans.rrset) print ( " response: " ,ans.response) 结果为 ( ' qname: ' , <DNS name www.baidu.com.> ) ( ' reclass: ' , 1 ) ( ' rdtype: ' , 1 ) ( ' rrset: ' , <DNS www.a.shifen.com. IN A RRset> ) ( ' response: ' , <DNS

python -- DNS处理模块dnspython

核能气质少年 提交于 2020-12-06 03:15:21
简介 dnspython – 是python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验 安装dnspython pip install dnspython 使用 常见的DNS解析类型包括A、MX、NS、CNAME (1)A记录的查询,实例如下: import dns.resolver domain = raw_input('Please input an domain: ') A = dns.resolver.query(domain, 'A') for i in A.response.answer: for j in i.items: print j.address 运行输入:www.baidu.com,输出结果如下: (2)MX记录 domain = raw_input('Please input an domain: ') MX = dns.resolver.query(domain, 'MX') for i in MX: print 'MX preference =', i.preference, 'mail exchanger =', i.exchange 运行输入:163.com,输出结果如下: (3)NS记录 print '*************NS****************' domain = raw_input(

python实现dns查询

最后都变了- 提交于 2020-04-30 14:43:01
dnspython模块中最常用的域名查询,它提供了一个DNS解析器类–resolver,使用resolver的query方法来实现域名的查询功能。 1.模块库安装 pip install dnspython 2.指定DNS服务器 my_resolver = dns.resolver.Resolver() my_resolver.nameservers = [DNS_Server] 3.query方法的定义 query(self,qname,rdtype=1,rdclass=1,tcp=False,source=None,raise_on_no_answer=True, source_port=0) 参数说明: qname表示待查询的域名,例如:www.baidu.com; rdtype用来指定待查询的类型,如A记录、MX记录、NS记录等; rdclass用来指定网络类型,如IN、CH、HS等,默认为IN; tcp用来指定查询时是否使用TCP协议,默认为False(即使用UDP); source和source_port用于指定查询源地址与端口,默认为查询设备IP和0端口raise_on_no_answer用来指定当查询无应答时是否触发异常。 4.代码实现 #!/usr/bin/env python # -*- coding: UTF-8 -*- #说明1

Tell urllib2 to use custom DNS

六月ゝ 毕业季﹏ 提交于 2019-12-17 07:15:18
问题 I'd like to tell urllib2.urlopen (or a custom opener ) to use 127.0.0.1 (or ::1 ) to resolve addresses. I wouldn't change my /etc/resolv.conf , however. One possible solution is to use a tool like dnspython to query addresses and httplib to build a custom url opener. I'd prefer telling urlopen to use a custom nameserver though. Any suggestions? 回答1: Looks like name resolution is ultimately handled by socket.create_connection . -> urllib2.urlopen -> httplib.HTTPConnection -> socket.create

Tell urllib2 to use custom DNS

会有一股神秘感。 提交于 2019-12-17 07:15:02
问题 I'd like to tell urllib2.urlopen (or a custom opener ) to use 127.0.0.1 (or ::1 ) to resolve addresses. I wouldn't change my /etc/resolv.conf , however. One possible solution is to use a tool like dnspython to query addresses and httplib to build a custom url opener. I'd prefer telling urlopen to use a custom nameserver though. Any suggestions? 回答1: Looks like name resolution is ultimately handled by socket.create_connection . -> urllib2.urlopen -> httplib.HTTPConnection -> socket.create

How do we get TXT, CNAME and SOA records from dnspython?

蹲街弑〆低调 提交于 2019-12-09 04:42:54
问题 I have a requirement to have a dns query function to query a server for various records. I figured out how to get the MX record (most of the examples show this), A record and NS record. How do I get the TXT, CNAME and SOA records? Sample code snippet: import dns.resolver answer=dns.resolver.query("google.com", "A") for data in answer: print data.address I tried replacing the query type with TXT and the data.address object with data.text, data.data etc, but ended up with attribute errors. What

pymongo - mongodb+srv “dnspython must be installed” error

爷,独闯天下 提交于 2019-12-08 15:21:05
问题 I am trying to connect MongoDB from Atlas But I encountered: dnspython must be installed error My mongo uri (mockup): mongodb+srv://abc:123@something.something.com/admin?retryWrites=True My pymongo version : 3.6.1 I have installed dnspython and done import dns Still, I am getting the error: dnspython module must be installed to use mongodb+srv:// URI 回答1: In order to use mongo+srv protocol, you need to install pymongo-srv Launch this command to do it with python 3: pip3 install pymongo[srv]

returning 'A' DNS record in dnspython

匆匆过客 提交于 2019-12-08 08:52:23
问题 I am using dnspython to get the 'A' record and return the result (IP address for a given domain). I have this simple testing python script: import dns.resolver def resolveDNS(): domain = "google.com" resolver = dns.resolver.Resolver(); answer = resolver.query(domain , "A") return answer resultDNS = resolveDNS() print resultDNS However, the output is: <dns.resolver.Answer object at 0x0000000004F56C50> I need to get the result as a string. If it is an array of strings, how to return it? 回答1:

填坑唯品会分布式调度Saturn

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 04:20:17
唯品会分布式调度Saturn的开发文档见: https://vipshop.github.io/Saturn/#/zh-cn/3.0/quickstart 这里面说要安装node.js 8.7.0+跟npm 5.4.2+ 但其实node.js 8.7.0就已经包含了npm 5.4.2,首先下载node.js 8.7.0 wget https://nodejs.org/dist/v8.7.0/node-v8.7.0-linux-x64.tar.gz 解压tar -xzvf node-v8.7.0-linux-x64.tar.gz mv node-v8.7.0-linux-x64 /usr/local/node-8.7 cd /usr/local/node-8.7/ 建立软链接 ln -s /usr/local/node-8.7/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm ln -s /usr/local/node-8.7/bin/node /usr/local/bin/node 修改vim /etc/profile PATH=/usr/local/node-8.7/bin:$PATH export PATH 保存退出,source /etc/profile [root@host2 node-8.7]# node -v