summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Hoffman <phoffman@proper.com>2021-10-14 10:49:53 -0700
committerPaul Hoffman <phoffman@proper.com>2021-10-14 10:49:53 -0700
commit4e38005e9d6d26ca7ddb16d4e0baf6c74ee8afa5 (patch)
treeba942c0a41551837cc1b6b9487ca333cc2495e07 /examples
parent41ba4f7a43f227a1871b1eff5672014738c8c371 (diff)
downloaddnspython-4e38005e9d6d26ca7ddb16d4e0baf6c74ee8afa5.tar.gz
Added examples of use_edns()
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/edns.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/examples/edns.py b/examples/edns.py
index b398885..a130f85 100755
--- a/examples/edns.py
+++ b/examples/edns.py
@@ -7,30 +7,42 @@ import dns.resolver
n = '.'
t = dns.rdatatype.SOA
-a = '199.7.83.42' # Address of l.root-servers.net
+l = '199.7.83.42' # Address of l.root-servers.net
+i = '149.20.1.73' # Address of ns1.isc.org, for COOKIEs
q_list = []
# A query without EDNS0
-q_list.append(dns.message.make_query(n, t))
+q_list.append((l, dns.message.make_query(n, t)))
# The same query, but with EDNS0 turned on with no options
-q_list.append(dns.message.make_query(n, t, use_edns=0))
+q_list.append((l,dns.message.make_query(n, t, use_edns=0)))
-# With an NSID option (use_edns=0 is not needed if options are specified)
-q_list.append(dns.message.make_query(n, t,\
- options=[dns.edns.GenericOption(dns.edns.OptionType.NSID, b'')]))
+# Use use_edns() to specify EDNS0 options, such as buffer size
+this_q = dns.message.make_query(n, t)
+this_q.use_edns(0, payload=2000)
+q_list.append((l, this_q))
+
+# With an NSID option
+# use_edns=0 is not needed if options are specified)
+q_list.append((l, dns.message.make_query(n, t,\
+ options=[dns.edns.GenericOption(dns.edns.OptionType.NSID, b'')])))
+
+# With an NSID option, but with use_edns() to specify the options
+this_q = dns.message.make_query(n, t)
+this_q.use_edns(0, options=[dns.edns.GenericOption(dns.edns.OptionType.NSID, b'')])
+q_list.append((l, this_q))
# With a COOKIE
-q_list.append(dns.message.make_query(n, t,\
- options=[dns.edns.GenericOption(dns.edns.OptionType.COOKIE, b'0xfe11ac99bebe3322')]))
+q_list.append((i, dns.message.make_query(n, t,\
+ options=[dns.edns.GenericOption(dns.edns.OptionType.COOKIE, b'0xfe11ac99bebe3322')])))
# With an ECS option using dns.edns.ECSOption to form the option
-q_list.append(dns.message.make_query(n, t,\
- options=[dns.edns.ECSOption('192.168.0.0', 20)]))
+q_list.append((l, dns.message.make_query(n, t,\
+ options=[dns.edns.ECSOption('192.168.0.0', 20)])))
-for q in q_list:
- r = dns.query.udp(q, a)
+for (addr, q) in q_list:
+ r = dns.query.udp(q, addr)
if not r.options:
print('No EDNS options returned')
else: