1

python更新中的以下代码

import dns.query
import dns.tsigkeyring
import dns.update
import sys
 keyring = dns.tsigkeyring.from_text({'host-example.' : 'XXXXXXXXXXXXXXXXXXXXXX=='})

update = dns.update.Update('dyn.test.example', keyring=keyring)
update.replace('host', 300, 'a', sys.argv[1])

 response = dns.query.tcp(update, '10.0.0.1')

但我不知道如何删除 dns 条目。

4

2 回答 2

3

delete()方法dns.update.Update可用于删除记录。

import dns.query
import dns.tsigkeyring
import dns.update

keyring = dns.tsigkeyring.from_text({'host-example.' : 'XXXXXXXXXXXXXXXXXXXXXX=='})
update = dns.update.Update('dyn.test.example', keyring=keyring)
update.delete('host', 'A')
response = dns.query.tcp(update, '10.0.0.1')
于 2013-12-17T23:31:21.540 回答
1

dns.update.Update的 delete 方法总是将名称作为第一个参数。其他参数可以是:

  • 没有
  • 数据集...
  • 数据...
  • rdtype,[字符串...]

来源:http ://www.dnspython.org/docs/1.15.0/

要从域 _acme-challenge.example.com 中删除内容为“Hello World”的特定 TXT 记录:

import dns.resolver
import dns.tsigkeyring
import dns.update
import dns.query

# Create the rdata object
txt_record = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.TXT, "Hello World")

# Initialize a new DNS update object
update = dns.update.Update('example.com', keyring=keyring)

# Delete the specific record passing in the rdata object
update.delete('_acme-challenge', txt_record)

# Send the request
reponse = dns.query.udp(update, '10.0.0.1', timeout=10)

# Check if the TXT record was successfully removed:
answers = dns.resolver.query('_acme-challenge.example.com', 'TXT')
txt_records = [txt_record.strings[0] for txt_record in answers]
if "Hello World" in txt_records:
    print "TXT record not successfully deleted"
else:
    print "TXT record successfully deleted"
于 2016-10-28T00:47:51.950 回答