Python dnspython

dnspython安装

pip3 install dnspython

dnspython常规用法:

import dns.resolver
a = dns.resolver(“www.baidu.com”, “A”)      #查询类型为A(IP地址)记录
for i in a.response.answer:     #查询回应信息
    for ii in i.items       #遍历回应信息
        print(ii)

mx = dns.resolver(“www.baidu.com”, “MX”)        #查询类型为MX(邮箱)记录
for i in mx:
    print(“MX preference = ”,i.preference, “mail exchanger = ”i.exchange)

ns = dns.resolver(“baidu.com”, “NS”)            
#查询类型为NS(域名)记录(只限一级域名)
for i in ns.response.answer:
    for ii in i.items   
        print(ii)

cnsme = dns.resolver(“www.baidu.com”, “CNSME”)  #查询类型为CNSME(别名)记录
for i in cnsme.response.answer: 
    for ii in i.items   
        print(ii)

你可能感兴趣的:(Python dnspython)