A记录:将主机名转换为IP地址
#!/usr/bin/python3.6.7
import dns.resolver
# 接收数据
domain = input("请输入一个域名>>>:")
dns_type = 'A'
query_object = dns.resolver.resolve(domain, rdtype=dns_type,lifetime=10)
for i in query_object:
print("解析记录为>>>:%s" % i)
import dns.resolver
from socket import gethostbyname
domain="12306.com"
dns_type='A'
CNAME=dns.resolver.resolve(domain,"A",lifetime=10)#子域名
ip_list=gethostbyname(domain)
print(ip_list)
query_object = dns.resolver.resolve(domain, rdtype=dns_type,lifetime=10)
for i in query_object:
print("解析记录为>>>:%s" % i)
MX记录:邮件交换记录,定义邮件服务器的域名
import dns.resolver
domain="qq.com"
MX=dns.resolver.resolve(domain,"MX",lifetime=10)
for mx in MX:
# print(mx)
#mx.preference代表邮件交换记录,mx.exchange代表邮件服务器域名
print(mx.preference,mx.exchange)