diff options
| author | Bob Halley <halley@dnspython.org> | 2016-12-30 12:35:52 -0800 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2016-12-30 12:35:52 -0800 |
| commit | e6cf2eb5bcc164e84672d1c2c2f653da6406220e (patch) | |
| tree | 3b33463b09f51b9ff54675d4512294d51f2a68b3 /examples/query_specific.py | |
| parent | 1af98a81d562b171abb914a6e04a508aca04c678 (diff) | |
| download | dnspython-e6cf2eb5bcc164e84672d1c2c2f653da6406220e.tar.gz | |
add example of querying a specific server
Diffstat (limited to 'examples/query_specific.py')
| -rw-r--r-- | examples/query_specific.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/query_specific.py b/examples/query_specific.py new file mode 100644 index 0000000..2da2cdf --- /dev/null +++ b/examples/query_specific.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +# Two ways of querying a specific nameserver. + +from __future__ import print_function + +import dns.message +import dns.rdataclass +import dns.rdatatype +import dns.query + +# This way is just like nslookup/dig: + +qname = dns.name.from_text('amazon.com') +q = dns.message.make_query(qname, dns.rdatatype.NS) +print('The query is:') +print(q) +print('') +r = dns.query.udp(q, '8.8.8.8') +print('The response is:') +print(r) +print('') +print('The nameservers are:') +ns_rrset = r.find_rrset(r.answer, qname, dns.rdataclass.IN, dns.rdatatype.NS) +for rr in ns_rrset: + print(rr.target) +print('') +print('') + +# A higher-level way + +import dns.resolver + +resolver = dns.resolver.Resolver(configure=False) +resolver.nameservers = ['8.8.8.8'] +answer = dns.resolver.query('amazon.com', 'NS') +print('The nameservers are:') +for rr in answer: + print(rr.target) |
