[Twisted-Python] twisted names - how to add answers to a message and send replies
exarkun at divmod.com
Thu Mar 13 10:48:05 EDT 2008
On Thu, 13 Mar 2008 07:52:24 +0000, Chris Dew <chris at sidwells.com> wrote:
>Thanks for your reply. I have tried setting answer to 1. I have included
>an amended version of my programme at the end of this email.
>When I run this, the server reports no error. When I 'dig @localhost
>foo.bar' I get the response:
>Could you point out my mistake? If it's a bug in twisted.names, I'm happy
>to look at fixing it (I've worked with the dns protocol at packet level
>before), but I first want to make sure that I am using the API correctly.
See below. I think it's a documentation deficiency, but probably not a
bug in the code.
>from twisted.internet.protocol import Protocol, Factory
>from twisted.internet import reactor
>from twisted.names.server import DNSServerFactory
>from twisted.names.dns import Query, DNSDatagramProtocol, RRHeader,
>Record_CNAME, Record_A, Message
>from twisted.names import dns
>from twisted.internet.interfaces import IAddress
> def messageReceived(self, m, protocol, addr):
> print m, dir(m), m.queries, m.answers
> # this should always answer 10.11.12.13, regardless of the query
> m.answer = 1
> protocol.transport.write(m.toStr(), addr)
Answers should be a list of RRHeaders, not bare Record_As.
>controller = Controller()
>if __name__ == "__main__":
> reactor.listenUDP(53, DNSDatagramProtocol(controller))
More information about the Twisted-Python