[Twisted-Python] DNS custom response (NXDOMAIN)

Tom Most twm at freecog.net
Wed Aug 5 17:48:04 MDT 2020


On Wed, Aug 5, 2020, at 3:59 PM, Rob Gormley wrote:
> But I tried with dns.Record_NULL to generate an NXDOMAIN-like response without success. How can I implement this?

You need to fail with AuthoritativeDomainError. The pieces go together something like this:

from twisted.names import dns, client, common

class MyResolver(ResolverBase):
    def _lookup(self, name, cls, record_type, timeout):
        # This says "my resolver can't handle that name, try somewhere else".
        # DNSServerFactory will try the caches or recurse to clients.
        return defer.fail(dns.DomainError(name))
        # This says "that name definitely doesn't exist".
        # The client will get NXDOMAIN
        return defer.fail(dns.AuthoritativeDomainError(name))


factory = DNSServerFactory(
    authorities=[MyResolver()],
    caches=[...],
   clients=[client.Resolver()],  # used to recurse
)

---Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20200805/3c225c23/attachment.htm>


More information about the Twisted-Python mailing list