[Twisted-Python] Handeling unresolved DNS queries?

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Thu Oct 22 09:55:16 EDT 2009


On 20 Oct, 07:50 pm, jesper at taxboel.dk wrote:
>Hi Guys,
>
>Im playing with a dns-cache script, that overrides DNS requests for 
>certain
>IP addresses.
>
>I would like to add functionality, so unresolved requests are sent to a
>spicific IP. How do I go about doing that?
>
>Is there a negative answer in the (udp) DNS protocol or am I forced to 
>use a
>timeout.

You've overridden writeMessage to inspect messages for answers and 
rewrite them if necessary.  You can recognize error responses by looking 
at the rCode attribute of the message object itself.  This will take on 
a value like dns.OK, dns.EFORMAT, dns.ESERVER, dns.ENAME, dns.ENOTIMP, 
or dns.EREFUSED.  You can handle these errors by making a request of 
another domain, although since writeMessage is a very low-level API in 
the process and not really intended to be overridden, I'm not sure how 
you'll insert the responses you get from these new requests into the 
original request/response process.

Jean-Paul



More information about the Twisted-Python mailing list