Skip to content Skip to sidebar Skip to footer

How Can I Check The Value Of A Dns Txt Record For A Host?

I'm looking to verify domain ownership via a script, specifically a Python script, and would like know how to lookup the value of a DNS TXT entry. I know there are services and web

Solution 1:

This is easy using dnspython. Here is an example:

importdns.resolverprintdns.resolver.query("aaa.asdflkjsadf.notatallsuspicio.us","TXT").response.answer[0][-1].strings[0]

This gives the following output:

PnCcKpPiGlLfApDbDoEcBbPjIfBnLpFaAaObAaAaMhNgNbIfPbHkMiEfPpGgJfOcPnLdDjBeHkOjFjIbPbIoKhIjHfJlAhAhFgGbGgNlMgKmFkLgNfBjMbCoBeNbGeOnAeHgLmKoFlLhLmDcKlEdEbDpFeHkFaBlGnHiOnChIoMlIhBgOnFfKoEhDnFkKfDaMgHbJhMgPgMjGiAoJpKjKkPaIcAdGiMbIbBbAfEiKjNbCeFoElKgOePmGjJaImL

Another option is to use dig in subprocess:

import subprocess

print subprocess.Popen(["dig","-t","txt","aaa.asdflkjsadf.notatallsuspicio.us","+short"], stdout=subprocess.PIPE).communicate()[0] 

Solution 2:

This may be overly simplified, but if all you want is a quick read of the TXT record and don't mind dealing with parsing the result separately:

nslookup -q=txt somedomain.com

I found this did what I needed, short & sweet.

Solution 3:

Found another way to get list of all TXT records for a domain using dnspython.

import dns.resolver
[dns_record.to_text() for dns_recordin dns.resolver.resolve("your-domain-here", "TXT").rrset]

Solution 4:

Something like this should work to at least get the value for the URL, I used google.com for the example.

import pycurl
import StringIO
url = "whatsmyip.us/dns_txt.php?host=google.com"
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HTTPHEADER, ["Accept:"])
txtcurl = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, txtcurl.write)
c.perform

data = txtcurl.getvalue()
data = data.replace("Done!", "")
print data

I did not test any of this but pulled it from a previous project.

Best of luck!

Post a Comment for "How Can I Check The Value Of A Dns Txt Record For A Host?"