[Twisted-Python] twisted names - how to add answers to a message and send replies
chris at sidwells.com
Wed Mar 12 04:04:21 EDT 2008
I have a small script which answers dns queries by returning the original
message. I have spent a couple of hours RTFMing, but I still cannot find
out how to correctly add answers to the message, before returning it.
I want to add an answer, either a Record_CNAME or Record_A, so as to produce
a trivial authoritative-only DNS server.
Adding a Record_XXX object to message.answers using the Array's 'append'
method produces a MalformedPacket (according to wireshark), though the
server does not throw any exceptions. (In this situation, the answer
count, as shown by dig, does rise to 1, even though no answer is displayed
[due to malformed packet?].)
Perhaps there is a completely different way to do this? Could I craft a
message with answers from scratch?
Any help appreciated,
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
# tried all sorts of things here
controller = Controller()
if __name__ == "__main__":
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python