2

I have the following simple Python script utilising the dnspython library:

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')

It works reasonably well as evidenced by the output of the host command, but for some reason my TXT value seems to be split on each space and each segment quoted. So the output from the host command looks like the following:

$ 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

Can anyone tell me why this is happening, and how to have it do the proper thing, which would be this:

$ 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

I must be missing something pretty obvious, but the documentation for dnspython is a little short on examples and much Googling has not revealed anything thus far. All help gratefully received.

4

1 回答 1

4

我似乎找到了答案。

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

耶 :-)

于 2013-06-22T20:58:06.163 回答