import dns.resolver
class Mydig:
def __init__(self):
self.data = {}
def get_dig_domain(self, domain_list):
for domain in domain_list:
res = dns.resolver.query(domain, 1)
for i in res.response.answer:
for j in i.items:
if j.rdtype == 5:
find_res = j.to_text().find('***dns.com')
self.data[domain] = 0 if find_res != -1 else -1
else:
self.data[domain] = -1
break
if __name__ == '__main__':
domain_list = [
"www.baidu.com",
"www.qq.com",
"aa.test.com",
]
obj = Mydig()
obj.get_dig_domain(domain_list)
print obj.data
本文转自cloves 51CTO博客,原文链接:http://blog.51cto.com/yeqing/1925162