[Twisted-Python] twisted names - how to add answers to a message and send replies
Chris Dew
chris at sidwells.com
Fri Mar 14 02:02:18 MDT 2008
I have it working now. I have attached a working programme below. (Note:
the RRHeader's name should be gathered from one of the queries, rather than
being hard-coded, as in my example below. I did it this way, as it more
obviously illustrates RRHeader's constructor.)
Thanks for your help,
Chris.
#!/usr/bin/python
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
class Controller(object):
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
m.answers.append(RRHeader(name="foo.bar", payload=Record_A(address="
10.11.12.13")))
protocol.transport.write(m.toStr(), addr)
controller = Controller()
if __name__ == "__main__":
reactor.listenUDP(53, DNSDatagramProtocol(controller))
reactor.run()
On 13/03/2008, Jean-Paul Calderone <exarkun at divmod.com> wrote:
>
> 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:
> >
>
> > [snip]
>
> >
> >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.
>
> > [snip]
>
> >
> >#!/usr/bin/python
> >
> >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
> >
> >class Controller(object):
> > 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
> > m.answers.append(Record_A(address="10.11.12.13"))
> > 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))
> > reactor.run()
> >
>
>
> Jean-Paul
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20080314/12ffbcd5/attachment.html>
More information about the Twisted-Python
mailing list