我有以下使用dnspython库的简单Python脚本:
import dns.query
import dns.tsigkeyring
import dns.update
import dns.rdatatype
import datetime
import sys
# Get data
current_ip = '1.2.3.4'
# Update DNS server
keyring = dns.tsigkeyring.from_text({
'my.key.name' : 'xxxxxxxxxxxxxxxxxxxx=='
})
update = dns.update.Update('dyn.example.com', keyring=keyring)
update.replace('myhost', 60, dns.rdatatype.A, current_ip)
update.replace('myhost', 60, dns.rdatatype.TXT, "xxx yyy zzz")
response = dns.query.tcp(update, 'ns.example.com')
主机命令的输出证明它工作得相当好,但由于某种原因,我的TXT值似乎在每个空格上被分开,每个段都被引用。因此host命令的输出如下所示:
$ host -t ANY myhost.dyn.example.com
myhost.dyn.example.com descriptive text "xxx" "yyy" "zzz"
myhost.dyn.example.com has address 1.2.3.4
任何人都可以告诉我为什么会这样,以及如何让它做正确的事情,这将是:
$ host -t ANY myhost.dyn.example.com
myhost.dyn.example.com descriptive text "xxx yyy zzz"
myhost.dyn.example.com has address 1.2.3.4
我必须遗漏一些非常明显的东西,但是dnspython的文档在示例上有点简短,而且谷歌搜索到目前为止还没有透露任何内容。感谢所有的帮助。
答案 0 :(得分:3)
我似乎找到了答案。
TXT记录的值需要用引号括起来 - 即字符串需要在其中包含引号:
update.replace('myhost', 60, dns.rdatatype.TXT, '"xxx yyy zzz"')
完美运作:
$ host -t ANY myhost.dyn.example.com
myhost.dyn.example.com descriptive text "xxx yyy zzz"
myhost.dyn.example.com has address 1.2.3.4
Yay: - )