CAA Record Checking

269 views
Skip to first unread message

Eddi Bento

unread,
Aug 16, 2017, 8:10:20 PM8/16/17
to dnspython-users
Hello.

I need some help with DNS Python.

I'm trying to run a DNS query to look up CAA records. I've used this code as a stand-alone python script which works and as some python code within Flask which I want to convert into a web app.

Here is the code for the simple script:


import
dns.resolver domaininput = 'monash.edu' resolver = dns.resolver.Resolver(configure=False) resolver.nameservers = ['8.8.8.8'] answer = dns.resolver.query(domaininput, 'CAA') for rdata in answer: print(rdata)

This works and provides me with all three CAA records assigned to this domain. In this example (at the time of posting this), there should be 3 records:


0 issue "quovadisglobal.com"
0 issuewild "quovadisglobal.com"
0 iodef "mailto:[redacted]"

When I use this code in my Flask webapp (which is running in a virtual environment), the same exact code only provides me with one of these results at random. Here is the code from app.py in Flask:


--snip--

    try:
        resolver = dns.resolver.Resolver(configure=False)
        resolver.nameservers = ['8.8.8.8']
        answer = dns.resolver.query(domaininput, 'CAA', raise_on_no_answer=True)
        for rdata in answer:
            result = str(rdata)
    except Exception as ex:
        result = str(ex)

--snip--


Does anyone have an idea why this is happening? Even if I use rdata.to_text, I receive only one at random.

Anand Buddhdev

unread,
Aug 17, 2017, 3:06:20 AM8/17/17
to Eddi Bento, dnspython-users
On 17/08/2017 02:10, Eddi Bento wrote:

Hi Eddi,

[snip]

> When I use this code in my Flask webapp (which is running in a virtual
> environment), the same exact code only provides me with one of these
> results at random. Here is the code from app.py in Flask:
>
> --snip--
>
> try:
> resolver = dns.resolver.Resolver(configure=False)
> resolver.nameservers = ['8.8.8.8']
> answer = dns.resolver.query(domaininput, 'CAA', raise_on_no_answer=True)
> for rdata in answer:
> result = str(rdata)
> except Exception as ex:
> result = str(ex)
>
> --snip--

The "for rdata in answer" loop above will overwrite "result" with each
iteration, so that at the end of the loop, "result" will only contain
one value. So this looks like a logic error in your Python code, rather
than a bug in dnspython. You can replace the for loop with a list
comprehension:

result = [ str(rdata) for rdata in answer ]

And this will make "result" a list containing all the RDATAs.

Regards,
Anand

Eddi Bento

unread,
Aug 17, 2017, 10:00:55 PM8/17/17
to dnspython-users
You are my hero. You were absolutely right. It was with my logic.  I used the code that you gave me which game a list and I simply did a for loop within the HTML in Flask to display it.

Thank you for your help! I really appreciate it!
Reply all
Reply to author
Forward
0 new messages