I have a small script which answers dns queries by returning the original message.&nbsp; 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&#39;s &#39;append&#39; method produces a MalformedPacket (according to wireshark), though the server does not throw any exceptions.&nbsp;&nbsp; (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?&nbsp; 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>&nbsp;&nbsp;&nbsp; def messageReceived(self, m, protocol, addr):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print m, dir(m), m.queries, m.answers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # tried all sorts of things here<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protocol.transport.write(m.toStr(), addr)<br><br>controller = Controller()<br><br>if __name__ == &quot;__main__&quot;:&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; reactor.listenUDP(53, DNSDatagramProtocol(controller))<br>&nbsp;&nbsp;&nbsp; reactor.run() <br>