import dns.resolverdomain =raw_input('Please input an domain: ')ns = dns.resolver.query(domain, 'NS')for i in ns.response.answer:for j in i.items:print(j.to_text())
测试:
[root@bogon dns]# python NS.pyPlease input an domain: baidu.com #智能输入一级域名ns4.baidu.com.ns3.baidu.com.ns2.baidu.com.dns.baidu.com.ns7.baidu.com.
查询A记录
import dns.resolverdomain =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)
查询 CNAME 记录
只限输入一级域名
import dns.resolverdomain =raw_input('please input a domain:')CNAME = dns.resolver.query(domain,'CNAME')for i in CNAME.response.answer:for j in i.items:print(j.to_text())
MX记录
import dns.resolverdomain =raw_input('Please input a domain')MX = dns.resolver.query(domain, 'MX')for i in MX:print('MX preference =', i.preference, 'mail exchanger =', i.exchange)