当前位置: 首页>>代码示例>>Python>>正文


Python Resolver.retry_servfail方法代码示例

本文整理汇总了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)
开发者ID:BobNovas,项目名称:ResolverCompare,代码行数:85,代码来源:ResolverCompare.py


注:本文中的dns.resolver.Resolver.retry_servfail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。