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


Python resolver.lifetime方法代码示例

本文整理汇总了Python中dns.resolver.lifetime方法的典型用法代码示例。如果您正苦于以下问题:Python resolver.lifetime方法的具体用法?Python resolver.lifetime怎么用?Python resolver.lifetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dns.resolver的用法示例。


在下文中一共展示了resolver.lifetime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def run(domain):
    ips = []
    resolver = dns.resolver.Resolver()
    resolver.lifetime = resolver.timeout = 5.0

    try:
        answers = resolver.query(domain, "A")
        for a in answers:
            ips.append(a.address)
        return ips
    except Exception:
        # print("Regular DNS Not Resolved\n")
    # Temporarily disabling - seems to cause massive delays at times.

    #     pass
    # try:
    #    ips = [ str(i[4][0]) for i in socket.getaddrinfo(domain, 443) ] 
    #    return ips
    # except Exception:
    #    print("Unable to Resolve\n")
       return ips 
开发者ID:depthsecurity,项目名称:armory,代码行数:23,代码来源:get_domain_ip.py

示例2: _get_a_record

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def _get_a_record(site, querytype='A', dnsserver=None):
    resolver = dns.resolver.Resolver()
    resolver.timeout = 5
    resolver.lifetime = 5

    if dnsserver:
        resolver.nameservers = [dnsserver]

    result = []
    while len(resolver.nameservers):
        try:
            resolved = resolver.query(site, querytype)
            print_debug(str(resolved.response))
            for item in resolved.rrset.items:
                result.append(item.to_text())
            return result

        except dns.exception.Timeout:
            print_debug("DNS Timeout for", site, "using", resolver.nameservers[0])
            resolver.nameservers.remove(resolver.nameservers[0])

    # If all the requests failed
    return "" 
开发者ID:ValdikSS,项目名称:blockcheck,代码行数:25,代码来源:blockcheck.py

示例3: DNSQuery

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def DNSQuery(to_addr):
    resolver = dns.resolver.Resolver()
    resolver.timeout = 3
    resolver.lifetime = 3

    Print(u"query MX of DNS for %s" % to_addr, sign=u"[+]")

    try:
        SMTP_addr = b'.'.join(dns.resolver.query(
            to_addr[to_addr.find(u"@")+1:], u'MX')[0].exchange.labels).decode(u"utf8")
        assert SMTP_addr != u""
    except Exception as e:
        Print(u"query MX of %s failed: " % to_addr + str(e),
              threshold=0, color=u"red", sign=u"[X]", flag=0)
        return 0

    Print(u"success", sign=u"  [*]")
    return SMTP_addr 
开发者ID:Macr0phag3,项目名称:email_hack,代码行数:20,代码来源:email_hacker.py

示例4: DNSQuery

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def DNSQuery(self):
        resolver = dns.resolver.Resolver()
        resolver.timeout = 3
        resolver.lifetime = 3

        try:
            host = self.to_addr[self.to_addr.find(u"@")+1:]

            # dns 列表
            self.SMTP_addrs = [b'.'.join(d.exchange.labels).decode(u"utf8") for d in dns.resolver.query(host, u'MX')]
            assert len(self.SMTP_addrs) > 1  # 确保 dns 有结果

        except Exception as e:
            return (False, u"get MX record of %s failed: " % self.to_addr + str(e))

        return (True, u"get MX record of %s success" % host) 
开发者ID:Macr0phag3,项目名称:email_hack,代码行数:18,代码来源:Email.py

示例5: __init__

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def __init__(self):
        super().__init__()
        self.parser.add_argument("query", type=str, help="Query string.")
        self.parser.add_argument("-t", "--rdtype", type=str, default=1, help="Query type.")
        self.parser.add_argument("-c", "--rdclass", type=str, default=1, help="Query class.")
        self.parser.add_argument("-m", "--metaquery", action="store_true", help="Execute as MetaQuery.")
        self.parser.add_argument("-s", "--source", type=str, default=socket.gethostbyname(socket.gethostname()), help="Source address.")
        self.parser.add_argument("-sP", "--source-port", type=int, default=random.randint(1, 65535), help="Source port.")
        self.parser.add_argument("--tcp", action="store_true", help="Use TCP to make the query.")
        self.parser.add_argument("-ns", "--nameservers", nargs="+", type=str, help="A list of nameservers to query. Each nameserver is a string which contains the IP address of a nameserver.")
        self.parser.add_argument("-p", "--port", type=int, default=53, help="The port to which to send queries (Defaults to 53).")
        self.parser.add_argument("-T", "--timeout", type=int, default=8, help="The number of seconds to wait for a response from a server, before timing out.")
        self.parser.add_argument("-l", "--lifetime", type=int, default=8, help="The total number of seconds to spend trying to get an answer to the question. If the lifetime expires, a Timeout exception will occur.")
        self.parser.add_argument("-e", "--edns", type=int, default=-1, help="The EDNS level to use (Defaults to -1, no Edns).")
        self.parser.add_argument("-eF", "--edns-flags", type=int, help="The EDNS flags.")
        self.parser.add_argument("-eP", "--edns-payload", type=int, default=0, help="The EDNS payload size (Defaults to 0).")
        self.parser.add_argument("-S", "--want-dnssec", action="store_true", help="Indicate that DNSSEC is desired.")
        self.parser.add_argument("-f", "--flags", type=int, default=None, help="The message flags to use (Defaults to None (i.e. not overwritten)).")
        self.parser.add_argument("-r", "--retry-servfail", action="store_true", help="Retry a nameserver if it says SERVFAIL.")
        self.parser.add_argument("-R", "--one-rr-per-rrset", action="store_true", help="Put each RR into its own RRset (Only useful when executing MetaQueries).")
        self.parser.add_argument("--filename", type=argparse.FileType("r"), help="The filename of a configuration file in standard /etc/resolv.conf format. This parameter is meaningful only when I{configure} is true and the platform is POSIX.")
        self.parser.add_argument("--configure-resolver", action="store_false", help="If True (the default), the resolver instance is configured in the normal fashion for the operating system the resolver is running on. (I.e. a /etc/resolv.conf file on POSIX systems and from the registry on Windows systems.") 
开发者ID:black-security,项目名称:cyber-security-framework,代码行数:24,代码来源:dnask.py

示例6: run

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def run(self):
        arguments = self.arguments.__dict__
        nameservers = arguments.get("nameservers")
        resolver = dns.resolver.Resolver(arguments.get("filename"), arguments.get("configure_resolver"))
        resolver.set_flags(arguments.get("flags"))
        resolver.use_edns(arguments.get("edns"), arguments.get("edns_flags"), arguments.get("edns_payload"))
        if nameservers:
            resolver.nameservers = nameservers
        resolver.port = arguments.get("port")
        resolver.timeout = arguments.get("timeout")
        resolver.lifetime = arguments.get("lifetime")
        resolver.retry_servfail = arguments.get("retry_servfail")
        if arguments.pop("metaquery"):
            kwargs = {v: arguments.get(k) for k, v in {"rdclass": "rdclass", "edns": "use_edns", "want_dnssec": "want_dnssec", "edns_flags": "ednsflags", "edns_payload": "request_payload"}.items()}
            message = dns.message.make_query(arguments.get("query"), arguments.get("rdtype"), **kwargs)
            kwargs = {k: arguments.get(k) for k in ["timeout", "port", "source", "source_port", "one_rr_per_rrset"]}
            if arguments.get("tcp"):
                resp = dns.query.tcp(message, resolver.nameservers[0], **kwargs)
            else:
                resp = dns.query.udp(message, resolver.nameservers[0], **kwargs)
            print(resp)
        else:
            kwargs = {k: arguments.get(k) for k in ["rdtype", "rdclass", "tcp", "source", "source_port"]}
            answer = resolver.query(arguments.pop("query"), **kwargs)
            print(answer.response) 
开发者ID:black-security,项目名称:cyber-security-framework,代码行数:27,代码来源:dnask.py

示例7: __init__

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def __init__(self, cfg, transact, reporter, code_id):
        logger.info('Resolver init')
        self.code_id = code_id
        self.transact = transact
        self.cfg = cfg
        self.reporter = reporter
        self.domain_sql = self.reporter.domain_rollback_sql(0, 'ignore')

        self.dns_servers = str(cfg.DNS()).split(' ')
        self.resolvers = [dns.resolver.Resolver(configure=False) for i in range(len(self.dns_servers))]
        for resolver, dns_server in zip(self.resolvers, self.dns_servers):
            resolver.nameservers = [dns_server]
            resolver.timeout = self.cfg.QueryTimeout()
            resolver.lifetime = self.cfg.QueryTimeout()

        logger.info('Resolver history.id: %s', self.code_id) 
开发者ID:Prototype-X,项目名称:blacklist-rkn-tool,代码行数:18,代码来源:resolver.py

示例8: _test_server

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def _test_server(self, server):
        resolver = dns.resolver.Resolver()
        resolver.lifetime = resolver.timeout = 10.0
        try:
            resolver.nameservers = [server]
            answers = resolver.query('public-dns-a.baidu.com')    # test lookup a existed domain
            if answers[0].address != '180.76.76.76':
                raise Exception('incorrect DNS response')
            try:
                resolver.query('test.bad.dns.lijiejie.com')    # Non-existed domain test
                with open('bad_dns_servers.txt', 'a') as f:
                    f.write(server + '\n')
                self._print_msg('[+] Bad DNS Server found %s' % server)
            except:
                self.dns_servers.append(server)
            self._print_msg('[+] Check DNS Server %s < OK >   Found %s' % (server.ljust(16), len(self.dns_servers)))
        except:
            self._print_msg('[+] Check DNS Server %s <Fail>   Found %s' % (server.ljust(16), len(self.dns_servers))) 
开发者ID:5alt,项目名称:ZeroScan,代码行数:20,代码来源:subDomainsBrute.py

示例9: resolve_ns

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def resolve_ns(data, t='A', timeout=HUNTER_RESOLVER_TIMEOUT):
    resolver = dns.resolver.Resolver()
    resolver.timeout = timeout
    resolver.lifetime = timeout
    resolver.search = []
    try:
        answers = resolver.query(data, t)
        resp = []
        for rdata in answers:
            resp.append(rdata)
    except (NoAnswer, NXDOMAIN, EmptyLabel, NoNameservers, Timeout) as e:
        if str(e).startswith('The DNS operation timed out after'):
            logger.info('{} - {} -- this may be normal'.format(data, e))
            return []

        if not str(e).startswith('The DNS response does not contain an answer to the question'):
            if not str(e).startswith('None of DNS query names exist'):
                logger.info('{} - {}'.format(data, e))
        return []

    return resp 
开发者ID:csirtgadgets,项目名称:bearded-avenger,代码行数:23,代码来源:__init__.py

示例10: run

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def run(self):
        resolver = dns.resolver.Resolver()
        resolver.timeout = self.dns_timeout
        # as per http://comments.gmane.org/gmane.comp.python.dnspython.user/144
        resolver.lifetime = self.dns_timeout
        try:
            log.debug("{}: Resolving {} with nameserver {}".format(
                self.name, self.target, self.dns_server))
            # it's a list
            resolver.nameservers = [self.dns_server, ]
            answer = resolver.query(self.target)
            for data in answer:
                out = '{} | {}'.format(self.target, data)
                self.res.append(out)
                # don't log to console, use file.
                # log.info(out)
        except dns.exception.Timeout as e:
            # we want to know if the DNS server is barfing
            errmsg = "{}: {}".format(self.target, e)
            self.err.append(errmsg)
            # log.warn(errmsg)
        except dns.exception.DNSException as e:
            log.debug("Error in thread {} when querying {}: {}".format(
                self.name, self.target, e)) 
开发者ID:lorenzog,项目名称:dns-parallel-prober,代码行数:26,代码来源:dns-queue.py

示例11: __init__

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def __init__(self, target, record_type, resolver_q, resolver_list, wildcards):
        multiprocessing.Process.__init__(self, target = self.run)
        self.daemon = True
        signal_init()

        self.time_to_die = False
        self.resolver_q = resolver_q
        self.wildcards = wildcards
        #Do we need wildcards for other types of records?
        #This needs testing!
        self.record_type = "A"
        if record_type == "AAAA":
            self.record_type = record_type
        self.resolver_list = resolver_list
        resolver = dns.resolver.Resolver()
        #The domain provided by the user.
        self.target = target
        #1 website in the world,  modify the following line when this status changes.
        #www.google.cn,  I'm looking at you ;)
        self.most_popular_website = "www.google.com"
        #We shouldn't need the backup_resolver, but we we can use them if need be.
        #We must have a resolver,  and localhost can work in some environments.
        self.backup_resolver = resolver.nameservers + ['127.0.0.1', '8.8.8.8', '8.8.4.4']
        #Ideally a nameserver should respond in less than 1 sec.
        resolver.timeout = 1
        resolver.lifetime = 1
        try:
            #Lets test the letancy of our connection.
            #Google's DNS server should be an ideal time test.
            resolver.nameservers = ['8.8.8.8']
            resolver.query(self.most_popular_website, self.record_type)
        except:
            #Our connection is slower than a junebug in molasses
            resolver = dns.resolver.Resolver()
        self.resolver = resolver 
开发者ID:kp625544,项目名称:subtake,代码行数:37,代码来源:subbrute.py

示例12: _setup_resolver

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def _setup_resolver(self, timeout=1):
        resolver = dns.resolver.Resolver(configure=False)
        resolver.timeout = timeout
        resolver.lifetime = timeout
        resolver.nameservers = [self.ns_ipaddr]
        self.resolver = resolver 
开发者ID:openstack,项目名称:designate,代码行数:8,代码来源:networking_test.py

示例13: dns_resolve

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def dns_resolve(host,
                query=None,
                ip_version=4,
                timeout=__DEFAULT_TIMEOUT__
                ):
    """
    Resolve a hostname to its A record, returning None if not found or
    there was a timeout.
    """
    __check_ip_version__(ip_version)

    if query is None:

        # The default query is for a host,

        return __dns_resolve_host(host, ip_version, timeout)

    else:

        # Any other explicit query value is forced to use DNS.

        try:
            resolver = dns.resolver.Resolver()
            resolver.timeout = timeout
            resolver.lifetime = timeout
            if query is None:
                query = 'A' if ip_version == 4 else 'AAAA'
            answers = resolver.query(host, query)
        except (dns.exception.Timeout,
                dns.name.EmptyLabel,
                dns.resolver.NXDOMAIN,
                dns.resolver.NoAnswer,
                dns.resolver.NoNameservers):
            return None

        return str(answers[0]) 
开发者ID:perfsonar,项目名称:pscheduler,代码行数:38,代码来源:psdns.py

示例14: get_resolver

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def get_resolver(nameserver):
    resolver = dns.resolver.Resolver()
    resolver.nameservers = [nameserver]
    resolver.timeout = args.timeout
    resolver.lifetime = args.timeout
    return resolver

# argparse 
开发者ID:mhelwig,项目名称:privdns,代码行数:10,代码来源:privdns.py

示例15: __init__

# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import lifetime [as 别名]
def __init__(self, target, options):
        self.start_time = time.time()
        self.target = target.strip()
        self.options = options
        self.ignore_intranet = options.i
        self.scan_count = self.found_count = 0
        self.console_width = getTerminalSize()[0] - 2
        self.resolvers = [dns.resolver.Resolver(configure=False) for _ in range(options.threads)]
        for _ in self.resolvers:
            _.lifetime = _.timeout = 10.0
        self.print_count = 0
        self.STOP_ME = False
        self._load_dns_servers()
        self._load_next_sub()
        self.queue = PriorityQueue()
        self.priority = 0
        self._load_sub_names()
        if options.output:
            outfile = options.output
        else:
            _name = os.path.basename(self.options.file).replace('subnames', '')
            if _name != '.txt':
                _name = '_' + _name
            outfile = target + _name if not options.full_scan else target + '_full' + _name
        self.outfile = open(outfile, 'w')
        self.ip_dict = {}
        self.found_subs = set()
        self.ex_resolver = dns.resolver.Resolver(configure=False)
        self.ex_resolver.nameservers = self.dns_servers 
开发者ID:5alt,项目名称:ZeroScan,代码行数:31,代码来源:subDomainsBrute.py


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