【问题标题】:dnspython dynamic TXT record update with spaces?dnspython动态TXT记录更新带空格?
【发布时间】:2013-06-22 18:38:35
【问题描述】:

我有以下使用 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 的文档在示例上有点短,而且到目前为止,谷歌搜索还没有透露任何内容。感谢所有帮助。

【问题讨论】:

    标签: python dnspython


    【解决方案1】:

    我似乎找到了答案。

    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
    

    耶 :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-18
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 2013-07-30
      • 2018-09-05
      相关资源
      最近更新 更多