记录 | 解释 |
---|---|
A | IP Address 记录,通过 hostname 获取到ip 地址。 |
AAAA | IP Address 记录,通过 hostname 获取到ipIPv6 地址. |
PTR | 反向dns解析, 使用ip 查找hostname记录。 |
NS | 负责域查询的名称服务器记录。NS记录是指定由哪个DNS服务器解析你的域名。 |
MX | 邮件交换器记录。服务器负责处理给定域的电子邮件。 |
SOA | 授权起始记录描述了区域管理员定义的有关区域的一些关键数据 |
CNAME | 规范名称或别名,这允许为资源提供备用名称。 |
TXT | 提供有关域的描述性数据的通用文本记录。一般指某个主机名或域名的说明 |
pip3 install dnspython
通过 dns.resolver.query来实现dns解析查询
query 参数解释
import dns.resolver
domain = 'www.biglittleant.cn'
qtype = 'A'
answer = dns.resolver.query(domain,qtype, raise_on_no_answer=False)
if answer.rrset is not None:
print(answer.rrset)
结果
biglittleant.github.io. 3600 IN A 185.199.108.153
biglittleant.github.io. 3600 IN A 185.199.109.153
biglittleant.github.io. 3600 IN A 185.199.110.153
biglittleant.github.io. 3600 IN A 185.199.111.153
第一步通过 reversename 拿到反转地址
from dns import reversename, resolver
ip = '13.229.188.59' #github.com 的ip
domain_address = reversename.from_address(ip)
print(domain_address)
qtype = 'PTR'
domain_name = str(resolver.query(domain_address, qtype)[0])
print(domain_name)
结果
59.188.229.13.in-addr.arpa.
ec2-13-229-188-59.ap-southeast-1.compute.amazonaws.com.
这里输入的域名得是二级域名。三级域名会报错。
import dns.resolver
myResolver = dns.resolver.Resolver()
myResolver.nameservers = ['223.5.5.5', '223.6.6.6']
myAnswers = myResolver.query("biglittleant.cn", "NS")
if myAnswers.rrset is not None:
print(myAnswers.rrset)
myAnswers = myResolver.query("qq.com", "NS")
if myAnswers.rrset is not None:
print(myAnswers.rrset)
biglittleant.cn. 3600 IN NS dns10.hichina.com.
biglittleant.cn. 3600 IN NS dns9.hichina.com.
qq.com. 3600 IN NS ns2.qq.com.
qq.com. 3600 IN NS ns1.qq.com.
qq.com. 3600 IN NS ns3.qq.com.
qq.com. 3600 IN NS ns4.qq.com.
搜索可知,ns.qq.com 是腾讯的dns服务器,hichina.com 是万网的dns服务器。
biglittleant.cn的解析记录是在阿里云,qq.com的解析记录是在腾讯云
这里输入的域名得是二级域名。三级域名会报错。
import dns.resolver
myResolver = dns.resolver.Resolver()
myAnswers = myResolver.query("qq.com", "TXT")
if myAnswers.rrset is not None:
print(myAnswers.rrset)
结果
qq.com. 31 IN TXT "v=spf1 include:spf.mail.qq.com -all"
import dns.resolver
myResolver = dns.resolver.Resolver()
myResolver.nameservers = ['223.5.5.5', '223.6.6.6']
myAnswers = myResolver.query("www.biglittleant.cn", "A")
if myAnswers.rrset is not None:
print(myAnswers.rrset)
结果
biglittleant.github.io. 600 IN A 185.199.110.153
biglittleant.github.io. 600 IN A 185.199.111.153
biglittleant.github.io. 600 IN A 185.199.109.153
biglittleant.github.io. 600 IN A 185.199.108.153
import dns.resolver
name = 'wwww.github.com'
for qtype in 'A', 'AAAA', 'CNAME', 'MX', 'NS', 'TXT', 'SOA':
print(qtype)
answer = dns.resolver.query(name, qtype, raise_on_no_answer=False)
if answer.rrset is not None:
print(answer.rrset)