2013-06-22 77 views
1

我有利用dnspython库中的以下简单的Python脚本:dnspython动态空间TXT记录更新?

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 -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的文档对于示例有点短,而Google的许多功能迄今尚未透露任何内容。感谢所有的帮助。

回答

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 

耶:-)