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


Python exception.DNSException方法代碼示例

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


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

示例1: zone_records

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def zone_records(self, zone):
        try:
            z = dns.zone.from_xfr(dns.query.xfr(self.master, zone.name,
                                                relativize=False),
                                  relativize=False)
        except DNSException:
            raise AxfrSourceZoneTransferFailed()

        records = []

        for (name, ttl, rdata) in z.iterate_rdatas():
            rdtype = dns.rdatatype.to_text(rdata.rdtype)
            records.append({
                "name": name.to_text(),
                "ttl": ttl,
                "type": rdtype,
                "value": rdata.to_text()
            })

        return records 
開發者ID:github,項目名稱:octodns,代碼行數:22,代碼來源:axfr.py

示例2: dns_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def dns_lookup(input, timeout=3, server=""):
    """Perform a simple DNS lookup, return results in a dictionary"""
    resolver = Resolver()
    resolver.timeout = float(timeout)
    resolver.lifetime = float(timeout)
    if server:
        resolver.nameservers = [server]
    try:
        records = resolver.query(input, "A")
        return {
            "addrs": [ii.address for ii in records],
            "error": "",
            "name": input,
        }
    except DNSException as e:
        return {
            "addrs": [],
            "error": repr(e),
            "name": input,
        } 
開發者ID:mpenning,項目名稱:ciscoconfparse,代碼行數:22,代碼來源:ccp_util.py

示例3: dns6_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def dns6_lookup(input, timeout=3, server=""):
    """Perform a simple DNS lookup, return results in a dictionary"""
    resolver = Resolver()
    resolver.timeout = float(timeout)
    resolver.lifetime = float(timeout)
    if server:
        resolver.nameservers = [server]
    try:
        records = resolver.query(input, "AAAA")
        return {
            "addrs": [ii.address for ii in records],
            "error": "",
            "name": input,
        }
    except DNSException as e:
        return {
            "addrs": [],
            "error": repr(e),
            "name": input,
        } 
開發者ID:mpenning,項目名稱:ciscoconfparse,代碼行數:22,代碼來源:ccp_util.py

示例4: run

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def run(self):
        lookups = self.rectypes or ['CNAME', 'A', 'AAAA']
        dnsname = self.domain
        if self.name is None:
            # Top-level, needs extra queries
            lookups += ['MX', 'SOA', 'NS', 'SRV', 'TXT', 'SPF', 'RRSIG', 'DS',
                        'DLV', 'DNSKEY']
        else:
            dnsname = '.'.join([self.name, dnsname])
        for query_type in set(lookups):
            resp = None
            LOG.debug("Checking %s %s", dnsname, query_type)
            try:
                resp = self.bruter.query(dnsname, query_type)
            except DNSException:
                continue
            except Exception:
                LOG.exception("While resolving %s %s", dnsname, query_type)
                continue
            self.bruter.on_result(self.domain, self.name, query_type, resp)
        self.bruter.on_finish() 
開發者ID:XiphosResearch,項目名稱:dnsbrute,代碼行數:23,代碼來源:__init__.py

示例5: _test_wildcard

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _test_wildcard(self, domain, name):
        """
        Determine if a subdomain returns a wildcard entry
        """
        for query_type in ['A', 'AAAA', 'CNAME']:
            dnsname = name + '.' + domain
            try:
                resp = self.query(dnsname, query_type)
            except DNSException:
                # This is expected, but we ignore return type
                continue
            except Exception:
                LOG.exception("Whoopsie while testing wildcard")
                continue
            for query_type, result in self._format_results(query_type, resp):
                self._add_wildcard(domain, query_type, result)
        self.on_finish() 
開發者ID:XiphosResearch,項目名稱:dnsbrute,代碼行數:19,代碼來源:__init__.py

示例6: time_resolve

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def time_resolve(args, server, name, rectype, tries=3):
    """
    Time how long it takes to resolve a name using the server
    """
    resolver = Resolver()
    resolver.timeout = args.timeout
    resolver.lifetime = args.timeout
    resolver.nameservers = [server]
    results = []

    while tries > 0:
        start = time.time()
        try:
            result = resolver.query(name, rectype)
        except DNSException as ex:
            end = time.time()
            LOG.debug("%s failed in %.2fs", server, end - start)
            result = ex
        else:
            end = time.time()
            LOG.debug("%s resolved %s %s in %.2fs", server, name, rectype, end - start)
        results.append((end - start, result))
        tries -= 1
    return server, check_results(results), results 
開發者ID:XiphosResearch,項目名稱:dnsbrute,代碼行數:26,代碼來源:checkresolvers.py

示例7: check_for_wildcards

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

示例8: _a_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _a_lookup(name: str) -> List[str]:
    try:
        return [e.address for e in resolver.query(name, 'A')]
    except DNSException:
        return [] 
開發者ID:PrivacyScore,項目名稱:PrivacyScore,代碼行數:7,代碼來源:network.py

示例9: _cname_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _cname_lookup(name: str) -> List[str]:
    try:
        return [e.to_text()[:-1].lower() for e in resolver.query(name, 'CNAME')]
    except DNSException:
        return [] 
開發者ID:PrivacyScore,項目名稱:PrivacyScore,代碼行數:7,代碼來源:network.py

示例10: _mx_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _mx_lookup(name: str) -> List[str]:
    try:
        return sorted([(e.preference, e.exchange.to_text()[:-1].lower())
                       for e in resolver.query(name, 'MX')], key=lambda v: v[0])
    except DNSException:
        return [] 
開發者ID:PrivacyScore,項目名稱:PrivacyScore,代碼行數:8,代碼來源:network.py

示例11: _reverse_lookup

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _reverse_lookup(ip: str) -> List[str]:
    try:
        address = reversename.from_address(ip).to_text()
        return [rev.to_text()[:-1].lower()
                for rev in resolver.query(address, 'PTR')]
    except DNSException:
        return [] 
開發者ID:PrivacyScore,項目名稱:PrivacyScore,代碼行數:9,代碼來源:network.py

示例12: _load_zone_file

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def _load_zone_file(self, zone_name):
        zonefiles = listdir(self.directory)
        if zone_name in zonefiles:
            try:
                z = dns.zone.from_file(join(self.directory, zone_name),
                                       zone_name, relativize=False,
                                       check_origin=self.check_origin)
            except DNSException as error:
                raise ZoneFileSourceLoadFailure(error)
        else:
            raise ZoneFileSourceNotFound()

        return z 
開發者ID:github,項目名稱:octodns,代碼行數:15,代碼來源:axfr.py

示例13: fqdn_to_ip

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def fqdn_to_ip(self, fqdn):
        try:
            dns_result = self._resolver.query(fqdn, 'A')
        except DNSException:
            return []
        ip_set = set()
        for i in dns_result:
            ip_set.add(str(i))
        return sorted(ip_set) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:11,代碼來源:enrich.py

示例14: test__enrich__with_fqdn_not_resolved

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def test__enrich__with_fqdn_not_resolved(self):
        self.enricher._resolver.query = mock.MagicMock(side_effect=DNSException)
        data = self.enricher.enrich(RecordDict({"fqdn": "cert.pl"}))
        self.assertEqualIncludingTypes(data, RecordDict({
            "enriched": ([], {}),
            "fqdn": "cert.pl"})) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:8,代碼來源:test_enrich.py

示例15: test__enrich__with_fqdn_from_url_not_resolved

# 需要導入模塊: from dns import exception [as 別名]
# 或者: from dns.exception import DNSException [as 別名]
def test__enrich__with_fqdn_from_url_not_resolved(self):
        self.enricher._resolver.query = mock.MagicMock(side_effect=DNSException)
        data = self.enricher.enrich(RecordDict({"url": "http://www.nask.pl/asd"}))
        self.assertEqualIncludingTypes(data, RecordDict({
            "enriched": (["fqdn"], {}),
            "url": "http://www.nask.pl/asd",
            "fqdn": "www.nask.pl"})) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:9,代碼來源:test_enrich.py


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