check for AA flag in dns.query response

746 views
Skip to first unread message

Emil Natan

unread,
Jan 5, 2016, 11:22:16 AM1/5/16
to dnspython-users
Hello group,

What I try to achieve is query authoritative DNS server using dnspython and check for authoritative answer (AA) flag in the response. So far I have:
1. create a query message:

>>> qm = dns.message.make_query('amazon.com', dns.rdatatype.SOA)

2. query specific server:

>>> qa = dns.query.udp(qm, '204.74.108.1', timeout=4)

3. apply to_text() function to qa:

>>> qa.to_text()
'id 53741\nopcode QUERY\nrcode NOERROR\nflags QR AA RD\n;QUESTION\namazon.com. IN SOA\n;ANSWER\namazon.com. 900 IN SOA dns-external-master.amazon.com. root.amazon.com. 2010113211 180 60 3024000 60\n;AUTHORITY\namazon.com. 3600 IN NS ns1.p31.dynect.net.\namazon.com. 3600 IN NS pdns6.ultradns.co.uk.\namazon.com. 3600 IN NS ns3.p31.dynect.net.\namazon.com. 3600 IN NS ns2.p31.dynect.net.\namazon.com. 3600 IN NS ns4.p31.dynect.net.\namazon.com. 3600 IN NS pdns1.ultradns.net.\n;ADDITIONAL' on the answer:

4. parse it for the AA flag

Is there a better alternative instead of 3) and 4)? Something providing explicitly the flags with no need to parse that long string.
Is there alternative way to achieve the same?

Thank you.

ena  

Anand Buddhdev

unread,
Jan 5, 2016, 11:29:04 AM1/5/16
to Emil Natan, dnspython-users
On 05/01/16 17:22, Emil Natan wrote:

Hi Emil,

> What I try to achieve is query authoritative DNS server using dnspython and
> check for authoritative answer (AA) flag in the response. So far I have:
> 1. create a query message:
>
>>>> qm = dns.message.make_query('amazon.com', dns.rdatatype.SOA)
>
> 2. query specific server:
>
>>>> qa = dns.query.udp(qm, '204.74.108.1', timeout=4)

[snip]

> Is there a better alternative instead of 3) and 4)? Something providing
> explicitly the flags with no need to parse that long string.
> Is there alternative way to achieve the same?

Do a bitwise AND:

qa.flags & dns.flags.AA

If that evaluates to "True" then the AA flags is set.

Regards,
Anand

Emil Natan

unread,
Jan 6, 2016, 11:16:41 AM1/6/16
to dnspython-users
Great. Thank you.

aid...@cs.stonybrook.edu

unread,
Feb 6, 2018, 6:12:39 PM2/6/18
to dnspython-users
dns.flags.to_text(qa.flags)
Reply all
Reply to author
Forward
0 new messages