diff options
| author | Bob Halley <halley@dnspython.org> | 2023-04-19 08:51:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-19 08:51:16 -0700 |
| commit | 6daff0efc931aca94b75fadf57fcfa95da9fce1b (patch) | |
| tree | e3d450e973e3d60479bcc5201d653b61e91be5ce /examples | |
| parent | 4783033f4365a9e9cd55e01bc6839f7df2cfd456 (diff) | |
| download | dnspython-6daff0efc931aca94b75fadf57fcfa95da9fce1b.tar.gz | |
Add make_resolver_at() and resolve_at(). (#926)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/async_dns.py | 4 | ||||
| -rw-r--r-- | examples/query_specific.py | 23 |
2 files changed, 23 insertions, 4 deletions
diff --git a/examples/async_dns.py b/examples/async_dns.py index f7e3fe5..297afcb 100644 --- a/examples/async_dns.py +++ b/examples/async_dns.py @@ -25,6 +25,10 @@ async def main(): print(a.response) zn = await dns.asyncresolver.zone_for_name(host) print(zn) + answer = await dns.asyncresolver.resolve_at("8.8.8.8", "amazon.com", "NS") + print("The amazon.com nameservers are:") + for rr in answer: + print(rr.target) if __name__ == "__main__": diff --git a/examples/query_specific.py b/examples/query_specific.py index 73dc351..2f13b24 100644 --- a/examples/query_specific.py +++ b/examples/query_specific.py @@ -25,16 +25,31 @@ for rr in ns_rrset: print("") print("") -# A higher-level way +# A higher-level way: import dns.resolver -resolver = dns.resolver.Resolver(configure=False) -resolver.nameservers = ["8.8.8.8"] -answer = resolver.resolve("amazon.com", "NS") +answer = dns.resolver.resolve_at("8.8.8.8", "amazon.com", "NS") print("The nameservers are:") for rr in answer: print(rr.target) +print("") +print("") + +# If you're going to make a bunch of queries to the server, make the resolver once +# and then use it multiple times: + +res = dns.resolver.make_resolver_at("dns.google") +answer = res.resolve("amazon.com", "NS") +print("The amazon.com nameservers are:") +for rr in answer: + print(rr.target) +answer = res.resolve("google.com", "NS") +print("The google.com nameservers are:") +for rr in answer: + print(rr.target) +print("") +print("") # Sending a query with the all flags set to 0. This is the easiest way # to make a query with the RD flag off. |
