【问题标题】:Checking for specific output from Python's DNS Resolver Query检查 Python 的 DNS 解析器查询的特定输出
【发布时间】:2014-04-11 04:05:56
【问题描述】:

我正在尝试编写一些要求用户输入特定域(例如 Google.com)的内容,如果 _spf.google.com 在 Google.com 的 SPF TXT 记录中,我希望它说“是的”。如果不是,我希望它说“不”。现在,代码会询问我的域,它会查找 SPF 记录,但我不能让它说“是的”。为什么不?我试过把它变成一个字符串,但即使这样也不能得到我想要的。我在这里做错了什么?

除此之外,你们会推荐什么是一个很好的起点,以便确定我需要编写什么代码来确定 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)

【问题讨论】:

    标签: python dns spf


    【解决方案1】:

    如果您的 if 在您的循环内:

        if "_spf.google.com" in data.to_text():
    

    如果您的 if 在您的循环之外:

    if any("_spf.google.com" in data.to_text() for data in answer):
    

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 2021-11-22
      • 1970-01-01
      • 2018-10-14
      相关资源
      最近更新 更多