Checking if SPF record exists?

489 views
Skip to first unread message

Chris Seymour

unread,
Dec 10, 2018, 8:50:40 AM12/10/18
to dnspython-users
Hello All,
Can anyone point me to an example or provide guidance on how I might be able to check if a SPF record wold exist for a domain?

Thank you

Anand Buddhdev

unread,
Dec 10, 2018, 9:21:00 AM12/10/18
to Chris Seymour, dnspython-users
On 10/12/2018 14:50, Chris Seymour wrote:

Hi Chris,

> Hello All,
> Can anyone point me to an example or provide guidance on how I might be
> able to check if a SPF record wold exist for a domain?

Assuming you want to do the equivalent of "dig ripe.net spf" using
dnspython:

#!/usr/bin/env python3
import dns.resolver

r = dns.resolver.Resolver()
try:
a = r.query('ripe.net', spf')
print(a.response)
except dns.resolver.NoAnswer:
print('No SPF record found for ripe.net')

Regards,
Anand Buddhdev
RIPE NCC

Chris Seymour

unread,
Dec 10, 2018, 9:31:43 AM12/10/18
to dnspython-users
Thank you Anand,
I have tried that but I do not get the expected results I am looking for.
I have a domain that I know has a SPF record in place (as checked by MXToolbox), but when I try to do the SPF query from dnspython I do not see the record.
Should I be also checking the TXT record as all I would like to show is the actual entry "v=spf1 ip...."

Thank you once again for you speedy response

Scott Kitterman

unread,
Dec 10, 2018, 9:51:40 AM12/10/18
to dnspython-users
Yes.

As of RFC 7208, type SPF is no longer used.

Scott K

Anand Buddhdev

unread,
Dec 10, 2018, 9:56:44 AM12/10/18
to Chris Seymour, dnspython-users
On 10/12/2018 15:31, Chris Seymour wrote:

Hi Chris,

> Thank you Anand,
> I have tried that but I do not get the expected results I am looking for.
> I have a domain that I know has a SPF record in place (as checked by
> MXToolbox), but when I try to do the SPF query from dnspython I do not see
> the record.
> Should I be also checking the TXT record as all I would like to show is the
> actual entry "v=spf1 ip...."

Then your original question was slightly incorrect. What you want to do
is look up the TXT record of the domain, and parse the results to see if
it contains SPF-related information. But I suspect you can handle that
now, by replacing QTYPE "spf" with QTYPE "txt" and then doing things
with the response.

Regards,
Anand

Chris Seymour

unread,
Dec 10, 2018, 11:14:14 AM12/10/18
to dnspython-users
Hello All,
So when I run the following in python 
check=dns.resolver.query(tryString, 'txt')
for x in check.response.answer:
 
print(x.to_text())



I get the following output
xxx.com. 360 IN TXT "MS=ms70102366"

I went through the response in the debugger and did not see anywhere v=spf1

I think I must be missing something

Thank you

Anand Buddhdev

unread,
Dec 10, 2018, 11:27:19 AM12/10/18
to Chris Seymour, dnspython-users
On 10/12/2018 17:14, Chris Seymour wrote:

> Hello All,
> So when I run the following in python
> check=dns.resolver.query(tryString, 'txt')
> for x in check.response.answer:
> print(x.to_text())
>
> *I get the following output*
>
> *xxx.com. 360 IN TXT "MS=ms70102366"*
>
> *I went through the response in the debugger and did not see anywhere v=spf1*

Don't hide the domain from us. It's in the DNS and public anyway, so do
everyone a favour and just tell us your domain name so we can help you
better.

Anand

Chris Seymour

unread,
Dec 10, 2018, 2:51:47 PM12/10/18
to dnspython-users
Hello Anand,
Unfortuantely, I am not able to disclose the name of the client (domain name)

But thatnk you for trying to assist.

I will keep digging.

Thank you

Chris Seymour

unread,
Dec 10, 2018, 3:07:08 PM12/10/18
to ana...@ripe.net, dnspyth...@googlegroups.com
Hello Anand,
Unfortunately, I am not able to share the actual client domain name.

But thank you for trying to assist me anyway.

Cheers
Reply all
Reply to author
Forward
0 new messages