'How do I create a DNS response packet

I have tried this, first is the dns request packet. The second packet is recognized also as a dns request packet. I want the second packet to be a dns response on the first packet

 dns = [
    IP(src=src, dst=dst) /
    UDP(sport=53, dport=2333) /
    DNS(id=1, rd=1, qd=DNSQR(qname='www.bittorrent.com')),

    IP(dst=src, src=dst) /
    UDP(sport=2333, dport=53) /
    DNS(id=1,rd=1,tc=0,ra=1,z=1,qdcount=0,ancount=0,nscount=0,arcount=0, qd=DNSQR(qname='www.bittorrent.com',qtype="A",qclass="IN")) / DNSRR(rrname="www.bittorrent.com")
]
wrpcap("test.pcap", dns)


Solution 1:[1]

Found some information on GitHub that could be some help with what your asking. This uses the dnslib module.

https://github.com/paulc/dnslib

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Barnett