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.<br><br>
I want to add an answer, either a Record_CNAME or Record_A, so as to produce a trivial authoritative-only DNS server. <br><br>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?].)<br>
<br>Perhaps there is a completely different way to do this? Could I craft a message with answers from scratch?<br><br>Any help appreciated,<br><br>Chris.<br><br><br>#!/usr/bin/python<br><br>from twisted.internet.protocol import Protocol, Factory<br>
from twisted.internet import reactor<br>from twisted.names.server import DNSServerFactory<br>from twisted.names.dns import Query, DNSDatagramProtocol, RRHeader, Record_CNAME, Record_A, Message<br>from twisted.names import dns<br>
from twisted.internet.interfaces import IAddress<br><br>class Controller(object):<br> def messageReceived(self, m, protocol, addr):<br> print m, dir(m), m.queries, m.answers<br> # tried all sorts of things here<br>
protocol.transport.write(m.toStr(), addr)<br><br>controller = Controller()<br><br>if __name__ == "__main__": <br> reactor.listenUDP(53, DNSDatagramProtocol(controller))<br> reactor.run() <br>