diff options
author | Paul Hoffman <phoffman@proper.com> | 2021-10-13 18:30:47 -0700 |
---|---|---|
committer | Paul Hoffman <phoffman@proper.com> | 2021-10-13 18:30:47 -0700 |
commit | 41ba4f7a43f227a1871b1eff5672014738c8c371 (patch) | |
tree | 22aab6b8b895b2b872f1c21f50af2679d54a768e | |
parent | 380846b2d6b550963d3e117f15abf8da26d18505 (diff) | |
download | dnspython-41ba4f7a43f227a1871b1eff5672014738c8c371.tar.gz |
First attempt at edns.py
-rwxr-xr-x | examples/edns.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/edns.py b/examples/edns.py new file mode 100755 index 0000000..b398885 --- /dev/null +++ b/examples/edns.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import dns.edns +import dns.message +import dns.query +import dns.resolver + +n = '.' +t = dns.rdatatype.SOA +a = '199.7.83.42' # Address of l.root-servers.net + +q_list = [] + +# A query without EDNS0 +q_list.append(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)) + +# 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'')])) + +# With a COOKIE +q_list.append(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)])) + +for q in q_list: + r = dns.query.udp(q, a) + if not r.options: + print('No EDNS options returned') + else: + for o in r.options: + print(o.otype.value, o.data) + print() + |