當前位置: 首頁>>代碼示例>>Python>>正文


Python resolver.NXDOMAIN屬性代碼示例

本文整理匯總了Python中dns.resolver.NXDOMAIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python resolver.NXDOMAIN屬性的具體用法?Python resolver.NXDOMAIN怎麽用?Python resolver.NXDOMAIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在dns.resolver的用法示例。


在下文中一共展示了resolver.NXDOMAIN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _check_one_challenge

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def _check_one_challenge(challenge: str, token: Optional[str]) -> bool:
    try:
        answers = resolver.query(challenge, "TXT")
    except (resolver.NXDOMAIN, resolver.NoAnswer):
        print("TXT {0} does not exist.".format(challenge))
        return False
    else:
        print("TXT {0} exists.".format(challenge))

    if token:
        validation_answers = [
            rdata
            for rdata in answers
            for txt_string in rdata.strings
            if txt_string.decode("utf-8") == token
        ]

        if not validation_answers:
            print("TXT {0} does not have the expected token value.".format(challenge))
            return False

        print("TXT {0} has the expected token value.")

    return True 
開發者ID:adferrand,項目名稱:dnsrobocert,代碼行數:26,代碼來源:hooks.py

示例2: process

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def process(self, headers, content):
        request = Services.get("request_factory")
        hostname = urlparse(request.url).hostname
        try:
            resolver = Resolver(configure=False)
            resolver.nameservers = [settings.dns_resolver]
            resolver.timeout = 2
            resolver.lifetime = 2

            dns_query = resolver.query(hostname + ".edgekey.net", "A")

            if len(dns_query) > 0:
                return "Akamai CDN"

        except NXDOMAIN:
            pass
        except NoAnswer:
            pass
        except Timeout:
            pass 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:22,代碼來源:akamai.py

示例3: process

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def process(self, headers, content):
        request = Services.get("request_factory")
        hostname = urlparse(request.url).hostname
        _ = False
        try:
            resolver = Resolver(configure=False)
            resolver.nameservers = [settings.dns_resolver]
            resolver.timeout = 2
            resolver.lifetime = 2

            dns_query = resolver.query(hostname, "CNAME")

            if len(dns_query) > 0:
                for answer in dns_query:
                    _ |= re.search(r"cloudfront\.net", str(answer), re.I) is not None
            if _:
                return "CloudFront CDN (Amazon)"
        except NoAnswer:
            pass
        except NXDOMAIN:
            pass
        except Timeout:
            pass 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:25,代碼來源:cloudfront.py

示例4: process

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def process(self, headers, content):
        request = Services.get("request_factory")
        hostname = urlparse(request.url).hostname
        _ = False

        try:
            resolver = Resolver(configure=False)
            resolver.nameservers = [settings.dns_resolver]
            resolver.timeout = 2
            resolver.lifetime = 2

            dns_query = resolver.query(hostname, "CNAME")
            if len(dns_query) > 0:
                for answer in dns_query:
                    _ |= re.search(r"azureedge\.net", str(answer), re.I) is not None
            if _:
                return "Azure CDN"
        except NoAnswer:
            pass
        except NXDOMAIN:
            pass
        except Timeout:
            pass 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:25,代碼來源:azure.py

示例5: process

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def process(self, headers, content):
        request = Services.get("request_factory")
        hostname = urlparse(request.url).hostname
        try:
            resolver = Resolver(configure=False)
            resolver.nameservers = [settings.dns_resolver]
            resolver.timeout = 2
            resolver.lifetime = 2
            dns_query = resolver.query(hostname + ".cdn.cloudflare.net", "A")

            if len(dns_query) > 0:
                return "Cloudflare CDN"

        except NXDOMAIN:
            pass
        except NoAnswer:
            pass
        except Timeout:
            pass 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:21,代碼來源:cloudflare.py

示例6: process

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def process(self, headers, content):
        request = Services.get("request_factory")
        hostname = urlparse(request.url).hostname
        _ = False
        try:
            resolver = Resolver(configure=False)
            resolver.nameservers = [settings.dns_resolver]
            resolver.timeout = 2
            resolver.lifetime = 2

            dns_query = resolver.query(hostname, "CNAME")
            if len(dns_query) > 0:
                for answer in dns_query:
                    _ |= re.search(r"fastly\.net", str(answer), re.I) is not None
            if _:
                return "Fastly CDN"
        except NoAnswer:
            pass
        except NXDOMAIN:
            pass
        except Timeout:
            pass 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:24,代碼來源:fastly.py

示例7: reflush

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def reflush(obj, nameserver):
    r = resolver.Resolver()
    r.nameservers = [nameserver]
    try:
        answers = r.query(obj.url, 'CNAME')
        for rdata in answers:
            return rdata.to_text()[:-1]
    except resolver.NoAnswer as e:
        try:
            answer = r.query(obj.url, 'A')
            for rr in answer:
                return rr.address
        except Exception as e:
            pass
    except resolver.NXDOMAIN as e:
        return ''
    return '' 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:19,代碼來源:tasks.py

示例8: test_rbl

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def test_rbl():
    """ handles failure ok, and handles lookups ok with dns module.
    """
    import mock
    from dns.resolver import NoAnswer, NXDOMAIN, NoNameservers

    from pygameweb.user.rbl import rbl

    assert rbl('127.0.0.1') is False
    assert rbl('') is False

    with mock.patch('dns.resolver.query') as query:
        query.side_effect = NoAnswer()
        assert rbl('192.168.0.1') is False
        query.side_effect = NXDOMAIN()
        assert rbl('192.168.0.1') is False
        query.side_effect = NoNameservers()
        assert rbl('192.168.0.1') is False

    with mock.patch('dns.resolver.query') as query:
        query.side_effect = '127.0.0.2'
        assert rbl('192.168.0.1') is True
        assert query.called 
開發者ID:pygame,項目名稱:pygameweb,代碼行數:25,代碼來源:test_rbl.py

示例9: check_for_wildcards

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def check_for_wildcards(args, server, name, rectype, tries=4):
    """
    Verify that the DNS server doesn't return wildcard results for domains
    which don't exist, it should correctly return NXDOMAIN.
    """
    resolver = Resolver()
    resolver.timeout = args.timeout
    resolver.lifetime = args.timeout
    resolver.nameservers = [server]
    nx_names = [base64.b32encode(
                    os.urandom(
                        random.randint(8, 10))
                ).strip('=').lower() + name
                for _ in range(0, tries)]
    correct_result_count = 0
    for check_nx_name in nx_names:
        try:
            result = resolver.query(check_nx_name, rectype)            
            return False  # Any valid response = immediate fail!
        except (NXDOMAIN, NoNameservers):
            correct_result_count += 1
        except DNSException:
            continue        
    return correct_result_count > (tries / 2.0) 
開發者ID:XiphosResearch,項目名稱:dnsbrute,代碼行數:26,代碼來源:checkresolvers.py

示例10: resolve_ns

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [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

示例11: get_mx_domains

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def get_mx_domains(domain, dns_resolver=_dns_resolver):
    """ Retrieve and return the MX records for a domain. """
    mx_records = []
    try:
        mx_records = dns_resolver().query(domain, 'MX')
    except NoNameservers:
        log.error('NoMXservers', domain=domain)
    except NXDOMAIN:
        log.error('No such domain', domain=domain)
    except Timeout:
        log.error('Time out during resolution', domain=domain)
        raise
    except NoAnswer:
        log.error('No answer from provider', domain=domain)
        mx_records = _fallback_get_mx_domains(domain)

    return [str(rdata.exchange).lower() for rdata in mx_records] 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:19,代碼來源:url.py

示例12: query_dns

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def query_dns(cls, domains, records):
        """
        Query DNS records for host.
        :param domains: Iterable of domains to get DNS Records for
        :param records: Iterable of DNS records to get from domain.
        """
        results = {k: set() for k in records}
        for record in records:
            for domain in domains:
                try:
                    answers = cls.resolver.query(domain, record)
                    for answer in answers:
                        # Add value to record type
                        results.get(record).add(answer)
                except (resolver.NoAnswer, resolver.NXDOMAIN, resolver.NoNameservers):
                    # Type of record doesn't fit domain or no answer from ns
                    continue

        return {k: v for k, v in results.items() if v} 
開發者ID:evyatarmeged,項目名稱:Raccoon,代碼行數:21,代碼來源:dns_handler.py

示例13: lookup_host

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def lookup_host(self, hostname, keep_going=True):
        result = set()

        for source in self.bind_addresses or [None]:
            if source is None:
                self.resolver.nameservers = self.nameservers
            else:
                self.resolver.nameservers = [str(dns) for dns in self.dns_servers if dns.version == source.version]
                if not self.resolver.nameservers:
                    continue

            for rectype in self.rectypes:
                try:
                    # print("Issuing query for hostname %r, rectype %r, source %r, search_domains %r, nameservers %r" % (
                    #     hostname, rectype, source, self.resolver.search_domains, self.resolver.nameservers), file=stderr)
                    a = self.resolver.query(hostname, rectype, source=str(source))
                    print("Got results: %r" % list(a), file=stderr)
                except (NXDOMAIN, NoAnswer):
                    pass
                except Timeout:
                    # No point in retrying with a different rectype if these DNS server(s) are not responding
                    break
                else:
                    result.update(ip_address(r.address) for r in a)
                if result and not keep_going:
                    return result

        return result or None 
開發者ID:dlenski,項目名稱:vpn-slice,代碼行數:30,代碼來源:dnspython.py

示例14: dns_record_exists

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def dns_record_exists(record):
    """Try and resolve a DNS record to see if it exists

    Args:
        record (str): DNS records to attempt to resolve

    Returns:
        `bool`
    """
    try:
        query(record)
        return True
    except NXDOMAIN:
        return False
# endregion 
開發者ID:RiotGames,項目名稱:cloud-inquisitor,代碼行數:17,代碼來源:__init__.py

示例15: _get_dns_txt_options

# 需要導入模塊: from dns import resolver [as 別名]
# 或者: from dns.resolver import NXDOMAIN [as 別名]
def _get_dns_txt_options(hostname):
    try:
        results = resolver.query(hostname, 'TXT')
    except (resolver.NoAnswer, resolver.NXDOMAIN):
        # No TXT records
        return None
    except Exception as exc:
        raise ConfigurationError(str(exc))
    if len(results) > 1:
        raise ConfigurationError('Only one TXT record is supported')
    return (
        b'&'.join([b''.join(res.strings) for res in results])).decode('utf-8') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:uri_parser.py


注:本文中的dns.resolver.NXDOMAIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。