How do I do dig TXT +short o-o.myaddr.l.google.com @8.8.4.4
in Python?
(That line resolves the hostname o-o.myaddr.l.google.com
through the DNS server 8.8.4.4
.)
You can use dnspython
, which is a DNS toolkit for Python. This can be installed via pip
.
pip install dnspython
You can then use dns.resolver.Resolver
class from this module to query the DNS records.
>>> import dns.resolver
>>> resolver = dns.resolver.Resolver()
>>> resolver.nameservers = ["8.8.4.4"]
>>> answer = resolver.resolve("<Your Domain>", 'TXT') # Query TXT record.