本文整理汇总了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
示例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,
}
示例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,
}
示例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()
示例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()
示例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
示例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)
示例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 []
示例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 []
示例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 []
示例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 []
示例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
示例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)
示例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"}))
示例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"}))