Creating DNS packet with dnslib python

2.9k Views Asked by At

Using dnslib with python 2.6

I created the following code

#!/usr/bin/env python

from dnslib import *
import sys

a = DNSRecord.question(sys.argv[1])

print a.pack()

when i try to do the following

a = DNSRecord.question(sys.argv[1],"A MX NS AAAA dnssec trace multiline")

dnslib.dns.DNSError: QTYPE: Invalid reverse lookup: [A MX NS AAAA dnssec trace multiline]

what i'd like to do is very simple

craft a packet with the following flags set in it and just pring the packed data

Is this possible using dnslib ?

1

There are 1 best solutions below

3
On BEST ANSWER
  1. trace and multiline are "dig"-specific flags that affect dig's behaviour and not the wire protocol.

  2. the dnssec flag sets the DNSSEC OK (aka DO) bit in an EDNS0 OPT RR that you would need to create and put in the "additional" section of the query. However EDNS0 support in dnslib is very poor.

  3. you can't put more than one QTYPE (i.e. A MX NS AAAA) in a single question - you'd need to ask a separate question for each.