本文整理汇总了Python中dns.resolver.Resolver方法的典型用法代码示例。如果您正苦于以下问题:Python resolver.Resolver方法的具体用法?Python resolver.Resolver怎么用?Python resolver.Resolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.resolver
的用法示例。
在下文中一共展示了resolver.Resolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例2: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例3: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例4: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例5: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例6: reflush
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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 ''
示例7: dns_lookup
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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,
}
示例8: dns6_lookup
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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,
}
示例9: time_resolve
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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
示例10: check_for_wildcards
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [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)
示例11: dns_cache_install
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [as 别名]
def dns_cache_install():
try:
from dns_cache.resolver import ExceptionCachingResolver
from dns import resolver as dnspython_resolver_module
if not dnspython_resolver_module.default_resolver:
dnspython_resolver_module.default_resolver = ExceptionCachingResolver()
del dnspython_resolver_module
except ImportError:
pass
try:
from dns.resolver import LRUCache, Resolver, override_system_resolver, _resolver, default_resolver
except ImportError:
return
if default_resolver:
if not default_resolver.cache:
default_resolver.cache = LRUCache()
resolver = default_resolver
elif _resolver and _resolver.cache:
resolver = _resolver
else:
resolver = Resolver()
resolver.cache = LRUCache()
override_system_resolver(resolver)
示例12: connect
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [as 别名]
def connect(self):
resolver = Resolver()
resolver.nameservers = self._dnsproxy
answer = resolver.query(self.host, 'A')
self.host = answer.rrset.items[0].address
self.sock = socket.create_connection((self.host, self.port))
示例13: configure
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [as 别名]
def configure(self, dns_servers, *, bind_addresses=None, search_domains=()):
super().configure(dns_servers, bind_addresses=bind_addresses, search_domains=search_domains)
self.resolver = Resolver(configure=False)
self.resolver.domain = root
self.resolver.search = [from_text(d) for d in search_domains]
self.rectypes = []
if self.bind_addresses is None or any(a.version == 4 for a in self.bind_addresses):
self.rectypes.append('A')
if self.bind_addresses is None or any(a.version == 6 for a in self.bind_addresses):
self.rectypes.append('AAAA')
示例14: dns_resolver
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [as 别名]
def dns_resolver():
"""
dns解析器
"""
resolver = Resolver()
resolver.nameservers = setting.resolver_nameservers
resolver.timeout = setting.resolver_timeout
resolver.lifetime = setting.resolver_lifetime
return resolver
示例15: reflush
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Resolver [as 别名]
def reflush(url, nameserver):
r = resolver.Resolver()
r.nameservers = [nameserver]
try:
answers = r.query(url, 'CNAME')
for rdata in answers:
return rdata.to_text()[:-1]
except resolver.NoAnswer as e:
return ''
except resolver.NXDOMAIN as e:
return ''
return ''