本文整理汇总了Python中dns.resolver.Resolver.retry_servfail方法的典型用法代码示例。如果您正苦于以下问题:Python Resolver.retry_servfail方法的具体用法?Python Resolver.retry_servfail怎么用?Python Resolver.retry_servfail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.resolver.Resolver
的用法示例。
在下文中一共展示了Resolver.retry_servfail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from dns.resolver import Resolver [as 别名]
# 或者: from dns.resolver.Resolver import retry_servfail [as 别名]
def main():
# parse and check command line args
(options, args) = parse_args()
if (len(options.ensure_value('resolvers', [])) != 2
or len(args) != 1):
usage()
sys.exit()
if options.run_tests:
test()
sys.exit()
#copy arg values from parser output
resolver_ips = options.resolvers
verbose = options.verbose
question_file = args[0]
ttl_tolerance = int(options.ttl_tolerance)
side_by_side = options.side_by_side
#create dns resolvers (no dnssec for now)
#source_ips is a list parallel to resolvers that contains the IPv4 address
#to bind the query source address to -so you can control which interface the
#query comes from - useful for testing on a machine with multiple nics.
resolvers = []
source_ips = []
for resolver_ip in resolver_ips:
resolver = Resolver()
if resolver_ip.find('/') > 0:
parts = resolver_ip.split('/')
resolver.nameservers = [parts[0]]
source_ips.append(parts[1])
else:
resolver.nameservers = [resolver_ip]
source_ips.append(None)
resolver.retry_servfail = True
#resolver.use_edns(0, DO, 1200)
resolver.lifetime = 5
resolvers.append(resolver)
#only compare 2 resolvers for now
if len(resolvers) > 2:
print("only 2 resolvers allowed for now..., picking first 2")
resolvers = resolvers[:2]
#loop over the question input and compare the results from the resolvers
lineno = 0
for line in file(question_file):
#allow blank lines or lines that start with #
if len(line.strip()) == 0 or line.lstrip().startswith("#"):
continue
#assume anything else is a question: <name> <rdtype> [<rdclass>]
parts = line.strip().split(' ')
name = parts[0].strip()
rdtype = parts[1].strip()
rdclass = parts[2].strip() if len(parts) > 2 else 'IN'
lineno += 1
results = []
rtt_time = []
for resolver, source_ip in zip(resolvers, source_ips):
try:
start_time = time.time()
result = resolver.query(name, rdtype, rdclass, source=source_ip, raise_on_no_answer=False)
end_time = time.time()
results.append(result)
rtt_time.append(end_time - start_time)
except NXDOMAIN, nxd:
results.append(nxd)
rtt_time.append(-1)
except YXDOMAIN, yxd:
results.append(yxd)
rtt_time.append(-1)
except NoAnswer, noa:
results.append(noa)
rtt_time.append(-1)