Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metebalci/f214f5e5732ae4fe1ca2dec82726f695 to your computer and use it in GitHub Desktop.
Save metebalci/f214f5e5732ae4fe1ca2dec82726f695 to your computer and use it in GitHub Desktop.
import dns
import dns.message
import dns.name
import dns.query
import dns.rdatatype
# name server we are sending the query
# google public dns
ns = "8.8.8.8"
# make the query
# qclass is not mentioned explicitly, it is IN=Internet by default
q = dns.message.make_query(
# for qname = www.metebalci.com
dns.name.from_text("www.metebalci.com"),
# for qtype = A
dns.rdatatype.A)
# send the query by udp, default port 53
ans = dns.query.udp(q, ns)
# below is a bit different than actual wire format of DNS message
# actually answer section contains individual resource records
# but I think this python package groups them into rrsets first
# resource record sets (rrset) in answer section
for rrset in ans.answer:
for rr in rrset:
print(rr.to_text())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment