user3097421
user3097421

Reputation: 151

Checking for specific output from Python's DNS Resolver Query

I'm trying to write something that will ask users to input a specific domain (say, Google.com), and if _spf.google.com is in the SPF TXT record for Google.com, I want it to say "Yup". If not, I want it to say "Nope." Right now, the code will ask me for the domain, and it'll look up the SPF record, but I can't get it to say "yup." Why not? I've tried turning it into a string, but even that wouldn't get me what I wanted. What am I doing wrong here?

To add to that, what would you guys recommend is a good jumping off point for figuring out what code I'd need to write to figure out how many DNS lookups an SPF record is ultimately using?

    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)

Upvotes: 2

Views: 1374

Answers (1)

Robᵩ
Robᵩ

Reputation: 168626

If your if is inside your loop:

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

If your if is outside your loop:

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

Upvotes: 2

Related Questions