本文整理汇总了Python中dns.resolver.Resolver.set_flags方法的典型用法代码示例。如果您正苦于以下问题:Python Resolver.set_flags方法的具体用法?Python Resolver.set_flags怎么用?Python Resolver.set_flags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.resolver.Resolver
的用法示例。
在下文中一共展示了Resolver.set_flags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_records
# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import set_flags [as 别名]
def get_records(host, port, proto='tcp'):
resolver = Resolver()
resolver.set_flags(flags.AD + flags.RD)
name = '_{}._{}.{}'.format(port, proto, host)
try:
rrset = resolver.query(name, rdtype=rdatatype.TLSA)
except NXDOMAIN:
log.debug('No record found for %s', name)
raise
except NoNameservers:
log.debug('No unbroken server for resolving %s', name)
# It may be because there is a bad dnssec key
resolver.set_flags(flags.CD + flags.RD)
rrset = resolver.query(name, rdtype=rdatatype.TLSA)
log.debug('Without validation we have an answer: %s', rrset)
for record in rrset:
log.debug(record)
secure = rrset.response.flags & flags.AD == flags.AD
if not secure:
log.warn('Not DNSSEC signed!')
return TLSAValidator([r for r in rrset], secure)
示例2: CustomResolver
# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import set_flags [as 别名]
class CustomResolver(object):
def __init__(self):
self.resolver = Resolver()
self.resolver.use_edns(0, 0, 4096)
self.resolver.set_flags(flags.AD + flags.RD)
self.degraded = Resolver()
self.degraded.use_edns(0, 0, 4096)
self.degraded.set_flags(flags.CD + flags.RD)
def query(self, fqdn, rdatatype=rdt.A, degraded=False):
log.debug('Query %s %s', fqdn, rdatatype)
try:
return self.resolver.query(fqdn, rdatatype)
except NoNameservers:
if degraded:
return self.degraded.query(fqdn, rdatatype)
raise
except NXDOMAIN:
if degraded:
return self.degraded.query(fqdn, rdatatype)
return None
def srv(self, name, domainname, proto='tcp'):
fqdn = '_{}._{}.{}'.format(name, proto, domainname)
return self.query(fqdn, rdt.SRV)
def tlsa(self, hostname, port, proto='tcp'):
fqdn = '_{}._{}.{}'.format(port, proto, hostname)
return self.query(fqdn, rdt.TLSA)
def mx(self, domainname):
return self.query(domainname, rdt.MX)