python - How to create DNS TXT record? -
i want create dns txt record type programmatically python code.
did not find data of how doing or specific format of txt record.
here how tried create txt record python:
# copy id of request packet+=self.data[:2] # add flags of response packet+= "\x81\x80" # questions , answers counts packet+='\x00\x01' packet+='\x00\x01' #no records follow packet+='\x00\x00' # additional records follow packet+='\x00\x00' #packet+='\x00\x01' (urllist,urldatalength) = decodequery(self.data) urlposition = urldatalength # original domain name question packet+=self.data[12:12+urldatalength+4] # pointer domain name packet+='\xc0\x0c' #response type ~~~~~~~~~~~~~~~~ # response type (txt) packet+='\x00\x10' #class packet+='\x00\x01' #ttl packet+='\x00\x00\x02\x58' #data length packet+='\x00\x04' #txt length packet+='\x04' packet+= 'hi'.encode('hex')
from dnslib (dns.py)
class txt(rd): """ dns txt record. pass in either single string, or tuple/list of strings. >>> txt('txtvers=1') "txtvers=1" >>> txt(('txtvers=1',)) "txtvers=1" >>> txt(['txtvers=1',]) "txtvers=1" >>> txt(['txtvers=1','swver=2.5']) "txtvers=1","swver=2.5" >>> = dnsrecord() >>> a.add_answer(*rr.fromzone('example.com 60 in txt "txtvers=1"')) >>> a.add_answer(*rr.fromzone('example.com 120 in txt "txtvers=1" "swver=2.3"')) >>> print(a) ;; ->>header<<- opcode: query, status: noerror, id: ... ;; flags: rd; query: 0, answer: 2, authority: 0, additional: 0 ;; answer section: example.com. 60 in txt "txtvers=1" example.com. 120 in txt "txtvers=1" "swver=2.3" """
Comments
Post a Comment