【发布时间】:2015-08-19 10:59:23
【问题描述】:
我想通过 python 代码以编程方式创建 dns TXT 记录类型。
我没有找到任何关于如何操作或TXT记录的具体格式是什么的数据。
这是我尝试通过 python 创建 TXT 记录的方法:
# copy the id of the request
packet+=self.data[:2]
# Add the flags of response
packet+= "\x81\x80"
# Questions and 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 to 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')
【问题讨论】:
-
你想达到什么目的?在脚本中编写 TXT 记录对您有什么好处?你想用python写一个DNS服务器吗?因为只有 DNS 服务器在组成带有回复记录的 DNS 数据包...
标签: python python-2.7 dns network-programming