Debian Codegraph @

examples/doh.py

raw
1 #!/usr/bin/env python3
2 #
3 # This is an example of sending DNS queries over HTTPS (DoH) with dnspython.
4 import httpx
5
6 import dns.message
7 import dns.query
8 import dns.rdatatype
9
10
11 def main():
12 where = "https://dns.google/dns-query"
13 qname = "example.com."
14 with httpx.Client() as client:
15 q = dns.message.make_query(qname, dns.rdatatype.A)
16 r = dns.query.https(q, where, session=client)
17 for answer in r.answer:
18 print(answer)
19
20 # ... do more lookups
21
22
23 if __name__ == "__main__":
24 main()