當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。