我正在编写一个代码,它将从域列表中解析CNAME,但我当前的脚本只解析list.txt的第一行,跳过其余的代码。
我通过运行"dl"来检查print(dl)将所有行导入列表中,但是dns.resolver并没有对每个列表数据进行检查。
我的样本代码是:
#/usr/bin/python3
import dns.resolver
d = open("list.txt" , "r")
dl = d.read().splitlines()
try:
for dom in dl:
answer = dns.resolver.resolve(dom, 'CNAME')
for rdata in answer:
print("CNAME", ':', rdata.to_text())
except Exception as e:
print(e)list.txt是:
www.google.com
www.github.com
www.facebook.com期望的产出是:
CNAME : www.gcaname.com
CNAME : www.gcaname.com
The DNS response does not contain an answer to the question: www.github.com. IN CNAME发布于 2022-01-27 09:57:11
这样做是有效的:
for dom in dl:
try:
answer = dns.resolver.resolve(dom, 'CNAME')
for rdata in answer:
print("CNAME of %s" % dom, ':', rdata.to_text())
except Exception as e:
pass发布于 2022-01-27 09:42:33
试试这个:
answers = dns.resolver.query('mail.google.com', 'CNAME')
print ' query qname:', answers.qname, ' num ans.', len(answers)
for rdata in answers:
print ' cname target address:', rdata.targethttps://stackoverflow.com/questions/70876278
复制相似问题