Created
July 17, 2018 09:04
-
-
Save metebalci/f214f5e5732ae4fe1ca2dec82726f695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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