Resolve dns (edns) with client subnet option in Python
dns, python
Solution
I'm the developer/maintainer of dnspython-clientsubnet. It is designed to be used in your code as an additive to dnspython. I've just released version 2.0.0 (after trying to do what you wanted) which makes everything much easier
- `pip install clientsubnetoption` (works for both Python2 & Python3)
Import `clientsubnetoption` and dependancies you'll need:
import dns
import clientsubnetoption
Setup your `ClientSubnetOption` with the information you want:
cso = clientsubnetoption.ClientSubnetOption('1.2.3.4')
Create your DNS packet:
message = dns.message.make_query('google.com', 'A')
Add the edns option:
message.use_edns(options=[cso])
Use `message` to make your query:
r = dns.query.udp(message, '8.8.8.8')
Option information is now at `r.options` and there can be multiple, so you may need to iterate through them to find the `ClientSubnetOption` object.
for options in r.options:
if isinstance(options, ClientSubnetOption):
# do stuff here
pass
The code in clientsubnetoption.py is there to act as a unit test and a testing tool for support of edns-clientsubnet, not because you have to use it that way.
Problem
I'm looking for an implementation in Python that would allow me to resolve a DNS address using an extension of DNS (EDNS) "client sub options" . This option allows better DNS-resolution for content delivery systems - and ultimately, faster internet routing. The motivation is better explained here: http://www.afasterinternet.com/howitworks.htm another name for this is "vandergaast-edns-client-subnet" an implementation for dig is available here: https://www.gsic.uva.es/~jnisigl/dig-edns-client-subnet.html I'm looking for a python implementation that would do the same.