本帖最后由 274920831 于 2018-07-03 18:04 编辑
根据这个链接:
https://blog.csdn.net/IMW_MG/article/details/78147764
中的这一段:
①A记录
关于A记录的实例代码如下: # -*- coding: utf-8 -*-# @Time : 2017/10/1 9:58
# @File : DNS.py
# @Software: PyCharm
import dns.resolver
domain = input("请输入域名地址:") # 输入域名地址
A = dns.resolver.query(domain, 'A') # 指定查询记录为A型
for i in A.response.answer: # 通过response.answer方法获取查询回应信息
# print(i)
for j in i.items:
print(j)
这里的dns.resolver是一个模块,我根据help>dns.resolver,可以查到这个模块的类和相应的方法,例如它的query方法 我想确认下response.answer是否是dns.resolver的方法,查得如下的信息: class Answer(__builtin__.object) | DNS stub resolver answer | | Instances of this class bundle up the result of a successful DNS | resolution. | | For convenience, the answer object implements much of the sequence | protocol, forwarding to its rrset. E.g. "for a in answer" is | equivalent to "for a in answer.rrset", "answer" is equivalent | to "answer.rrset", and "answer[i:j]" is equivalent to | "answer.rrset[i:j]". | | Note that CNAMEs or DNAMEs in the response may mean that answer | node's name might not be the query name. | | @ivar qname: The query name | @type qname: dns.name.Name object | @ivar rdtype: The query type | @type rdtype: int | @ivar rdclass: The query class | @type rdclass: int | @ivar response: The response message | @type response: dns.message.Message object | @ivar rrset: The answer | @type rrset: dns.rrset.RRset object | @ivar expiration: The time when the answer expires | @type expiration: float (seconds since the epoch) | @ivar canonical_name: The canonical name of the query name | @type canonical_name: dns.name.Name object 第一个问题: 这里的红色的Answer是一个类,那么下面的@ivar response和@type response是代表什么意思?如何来判断response.answer是一个方法? 第二个问题: A = dns.resolver.query(domain, 'A') 这里的A是一个对像吗?依据我的理解: 对像 = 模块.类() 而这里的格式是 : A = 模块.方法(参数) ,那么这样的格式也可以生成对像吗?
第三个问题: A = dns.resolver.query(domain, 'A') 如果这里的A是一个对像,按照这行的意思: for i in A.response.answer: A 做为一个对像,还是可以继续使用dns.resolver的方法response.answer,可以这样理解吗?
|