我正在尝试编写一些内容,要求用户输入特定域(例如 Google.com),如果 _spf.google.com 位于 Google.com 的 SPF TXT 记录中,我希望它说“是的”。如果没有,我希望它说“不”。现在,代码会询问我域名,并且会查找 SPF 记录,但我无法让它说"is"。为什么不?我尝试过将其变成字符串,但即使这样也无法得到我想要的东西。我在这里做错了什么?
除此之外,你们建议什么是一个很好的起点,用于确定我需要编写哪些代码来确定 SPF 记录最终使用了多少次 DNS 查找?
import dns.resolver
question= raw_input("What domain do you want? ")
def PrintandGoogle(question):
answer=dns.resolver.query(question,"TXT")
for data in answer:
print data
if "_spf.google.com" in answer:
print "Yup."
else:
print "Nope."
printAndGoogle(question)
最佳答案
如果您的 if
位于循环内:
if "_spf.google.com" in data.to_text():
如果您的 if
位于循环之外:
if any("_spf.google.com" in data.to_text() for data in answer):
关于python - 检查 Python DNS 解析器查询的特定输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003286/