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


Python dns.resolver方法代码示例

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


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

示例1: test_recursive_query_basic_failure

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def test_recursive_query_basic_failure(self):
        resolver = dns.resolver.Resolver()
        domain = dns.name.from_text('example.com.')
        record_type = 'NS'

        with unittest.mock.patch.object(fierce, 'query', return_value=None) as mock_method:
            result = fierce.recursive_query(resolver, domain, record_type=record_type)

        expected = [
            unittest.mock.call(resolver, 'example.com.', record_type, tcp=False),
            unittest.mock.call(resolver, 'com.', record_type, tcp=False),
            unittest.mock.call(resolver, '', record_type, tcp=False),
        ]

        mock_method.assert_has_calls(expected)
        assert result is None 
开发者ID:mschwager,项目名称:fierce,代码行数:18,代码来源:test_fierce.py

示例2: resolve

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def resolve(resolver,ip, quiet=False):
    try:
        answer = resolver.query(ip.reverse_pointer,'ptr')
        if not quiet:
            print("[+] " + str(ip) + " : " + str(answer[0]))
        return 1, str(answer[0])
    except dns.resolver.NXDOMAIN:
        if not quiet:
            print("[.] Resolved but no entry for " + str(ip))
        return 2, None
    except dns.resolver.NoNameservers:
        if not quiet:
            print("[-] Answer refused for " + str(ip))
        return 3, None
    except dns.resolver.NoAnswer:
        if not quiet:
            print("[-] No answer section for " + str(ip))
        return 4, None
    except dns.exception.Timeout:
        if not quiet:
            print("[-] Timeout")
        return 5, None

# log output to file 
开发者ID:mhelwig,项目名称:privdns,代码行数:26,代码来源:privdns.py

示例3: __init__

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def __init__(self, *a, **kw):
        """Configure the backend"""
        super(GdnsdBackend, self).__init__(*a, **kw)

        self._gdnsd_cmd_name = cfg.CONF[CFG_GROUP_NAME].gdnsd_cmd_name
        LOG.info("gdnsd command: %r", self._gdnsd_cmd_name)
        self._confdir_path = cfg.CONF[CFG_GROUP_NAME].confdir_path
        self._zonedir_path = os.path.join(self._confdir_path, 'zones')
        LOG.info("gdnsd conf directory: %r", self._confdir_path)
        self._resolver = dns.resolver.Resolver(configure=False)
        self._resolver.timeout = SOA_QUERY_TIMEOUT
        self._resolver.lifetime = SOA_QUERY_TIMEOUT
        self._resolver.nameservers = [
            cfg.CONF[CFG_GROUP_NAME].query_destination
        ]
        LOG.info("Resolvers: %r", self._resolver.nameservers)
        self._check_dirs(self._zonedir_path) 
开发者ID:openstack,项目名称:designate,代码行数:19,代码来源:impl_gdnsd.py

示例4: test_recursive_query_long_domain_failure

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def test_recursive_query_long_domain_failure(self):
        resolver = dns.resolver.Resolver()
        domain = dns.name.from_text('sd1.sd2.example.com.')
        record_type = 'NS'

        with unittest.mock.patch.object(fierce, 'query', return_value=None) as mock_method:
            result = fierce.recursive_query(resolver, domain, record_type=record_type)

        expected = [
            unittest.mock.call(resolver, 'sd1.sd2.example.com.', record_type, tcp=False),
            unittest.mock.call(resolver, 'sd2.example.com.', record_type, tcp=False),
            unittest.mock.call(resolver, 'example.com.', record_type, tcp=False),
            unittest.mock.call(resolver, 'com.', record_type, tcp=False),
            unittest.mock.call(resolver, '', record_type, tcp=False),
        ]

        mock_method.assert_has_calls(expected)
        assert result is None 
开发者ID:mschwager,项目名称:fierce,代码行数:20,代码来源:test_fierce.py

示例5: test_recursive_query_basic_success

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def test_recursive_query_basic_success(self):
        resolver = dns.resolver.Resolver()
        domain = dns.name.from_text('example.com.')
        record_type = 'NS'
        good_response = unittest.mock.MagicMock()
        side_effect = [
            None,
            good_response,
            None,
        ]

        with unittest.mock.patch.object(fierce, 'query', side_effect=side_effect) as mock_method:
            result = fierce.recursive_query(resolver, domain, record_type=record_type)

        expected = [
            unittest.mock.call(resolver, 'example.com.', record_type, tcp=False),
            unittest.mock.call(resolver, 'com.', record_type, tcp=False),
        ]

        mock_method.assert_has_calls(expected)
        assert result == good_response 
开发者ID:mschwager,项目名称:fierce,代码行数:23,代码来源:test_fierce.py

示例6: test_find_nearby_basic

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def test_find_nearby_basic(self):
        resolver = 'unused'
        ips = [
            ipaddress.IPv4Address('192.168.1.0'),
            ipaddress.IPv4Address('192.168.1.1'),
        ]
        side_effect = [
            [MockAnswer('sd1.example.com.')],
            [MockAnswer('sd2.example.com.')],
        ]

        with unittest.mock.patch.object(fierce, 'reverse_query', side_effect=side_effect):
            result = fierce.find_nearby(resolver, ips)

        expected = {
            '192.168.1.0': 'sd1.example.com.',
            '192.168.1.1': 'sd2.example.com.',
        }

        assert expected == result 
开发者ID:mschwager,项目名称:fierce,代码行数:22,代码来源:test_fierce.py

示例7: test_find_nearby_filter_func

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def test_find_nearby_filter_func(self):
        resolver = 'unused'
        ips = [
            ipaddress.IPv4Address('192.168.1.0'),
            ipaddress.IPv4Address('192.168.1.1'),
        ]
        side_effect = [
            [MockAnswer('sd1.example.com.')],
            [MockAnswer('sd2.example.com.')],
        ]

        def filter_func(reverse_result):
            return reverse_result == 'sd1.example.com.'

        with unittest.mock.patch.object(fierce, 'reverse_query', side_effect=side_effect):
            result = fierce.find_nearby(resolver, ips, filter_func=filter_func)

        expected = {
            '192.168.1.0': 'sd1.example.com.',
        }

        assert expected == result 
开发者ID:mschwager,项目名称:fierce,代码行数:24,代码来源:test_fierce.py

示例8: mass_resolve

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def mass_resolve(self, domains, num_threads=100):
        threads = []
        for _ in range(0, num_threads):
            logging.debug("Starting thread {}".format(_))
            t = threading.Thread(target=self.consumer)
            t.start()
            threads.append(t)

        for d in domains:
            logging.debug("Putting {} in resolver queue".format(d))
            self.queue.put((d.value, 'A'), True)
            # Avoid ns1.ns1.ns1.domain.com style recursions
            if d.value.count('.') <= 2:
                self.queue.put((d.value, 'NS'), True)

        for t in threads:
            t.join()

        return self.results 
开发者ID:yeti-platform,项目名称:yeti,代码行数:21,代码来源:resolve_hostnames.py

示例9: _has_dns_propagated

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def _has_dns_propagated(fqdn, token):
    txt_records = []
    try:
        dns_resolver = dns.resolver.Resolver()
        dns_resolver.nameservers = [get_authoritative_nameserver(fqdn)]
        dns_response = dns_resolver.query(fqdn, "TXT")
        for rdata in dns_response:
            for txt_record in rdata.strings:
                txt_records.append(txt_record.decode("utf-8"))
    except dns.exception.DNSException:
        metrics.send("has_dns_propagated_fail", "counter", 1, metric_tags={"dns": fqdn})
        return False

    for txt_record in txt_records:
        if txt_record == token:
            metrics.send("has_dns_propagated_success", "counter", 1, metric_tags={"dns": fqdn})
            return True

    return False 
开发者ID:Netflix,项目名称:lemur,代码行数:21,代码来源:dyn.py

示例10: check_takeover

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def check_takeover(domain, target):
    dnsResolver = dns.resolver.Resolver()
    dnsResolver.nameservers = ['8.8.8.8', '8.8.4.4']
    try:
        # Query the DNS resolver to check if subdomain is a CNAME
        answers = dnsResolver.query(target, 'CNAME')
        # Query whois
        for rdata in answers:
            output = '{:s}'.format(rdata.target)
            # If scope is/not in output splash some crap out
            if not domain in output:
                return output
    # To solve those "BLAH SUBDOMAIN IS NO CNAME" errors
    except dns.resolver.NoAnswer:
        pass
    except dns.resolver.NXDOMAIN:
        pass
    return 0 
开发者ID:flipkart-incubator,项目名称:RTA,代码行数:20,代码来源:subtakeover.py

示例11: __call__

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def __call__(self):
            """Execute the test step.

            Overrides the base class implementation.
            """
            self.set_started()

            self.resolver = dns.resolver.Resolver()
            self.resolver.nameserver = self._get_nameservers()
            self.logger.info('Querying name servers of {} started'.format(self.hostname))
            start_time = datetime.now()
            query_result = self.resolver.query(self.hostname, 'A')
            end_time = datetime.now()
            self.set_passed()
            self.logger.info('Querying name servers of {} finished successfully; found IPs: {}'
                             .format(self.hostname, ', '.join([str(rdata) for rdata in query_result])))
            self.duration = end_time - start_time 
开发者ID:Dynatrace,项目名称:dynatrace-api,代码行数:19,代码来源:dns_test.py

示例12: __init__

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def __init__(self):
        md = ProcessorDescription(
            module_name="DNSResolver",
            description="Resolve inbound domains",
            authors=["Silas Cutler"],
            version="0.1"
        )
        Processor.__init__(self, md)
        self.types = ['domains']
        self.parse_settings()
        self.dns = dns.resolver.Resolver()
        self.dns.nameservers = self.nameservers
        self.dns.timeout = 2
        self.dns.lifetime = 2

    # Module Settings 
开发者ID:silascutler,项目名称:MalPipe,代码行数:18,代码来源:DNSResolve.py

示例13: dns_lookup

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def dns_lookup(nameserver, name):
    """
    This function performs the actual DNS lookup when called in a threadpool
    by the fast_dns_lookup function.
    """
    res = dns.resolver.Resolver()
    res.timeout = 10
    res.nameservers = [nameserver]

    try:
        res.query(name)
        # If no exception is thrown, return the valid name
        return name
    except dns.resolver.NXDOMAIN:
        return ''
    except dns.exception.Timeout:
        print("    [!] DNS Timeout on {}. Investigate if there are many"
              " of these.".format(name)) 
开发者ID:initstring,项目名称:cloud_enum,代码行数:20,代码来源:utils.py

示例14: _dns_query

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def _dns_query(target_hostname, query_type, target_nameserver):
    res = dns.resolver.Resolver(configure=False)
    res.nameservers = [target_nameserver]
    result = res.query(
        qname=target_hostname,
        rdtype=query_type,
        raise_on_no_answer=False,
    )
    return result 
开发者ID:mandatoryprogrammer,项目名称:TrustTrees,代码行数:11,代码来源:dns.py

示例15: _try_to_get_first_ip_for_hostname

# 需要导入模块: import dns [as 别名]
# 或者: from dns import resolver [as 别名]
def _try_to_get_first_ip_for_hostname(hostname):
    """
    :returns: string
    e.g.
        "1.2.3.4" or ""
    """
    try:
        answer = _dns_query(
            hostname,
            query_type='A',
            target_nameserver=secrets.choice(global_state.RESOLVERS),
        )
        if answer.rrset:
            return str(answer.rrset[0])
    except (
        dns.resolver.NoNameservers,
        dns.resolver.NXDOMAIN,
        dns.resolver.Timeout,
        dns.resolver.YXDOMAIN,
    ):
        pass
    return '' 
开发者ID:mandatoryprogrammer,项目名称:TrustTrees,代码行数:24,代码来源:dns.py


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