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"