本文整理汇总了Python中dns.resolver.Timeout方法的典型用法代码示例。如果您正苦于以下问题:Python resolver.Timeout方法的具体用法?Python resolver.Timeout怎么用?Python resolver.Timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.resolver
的用法示例。
在下文中一共展示了resolver.Timeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [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 Timeout [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 Timeout [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 Timeout [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 Timeout [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: resolve_ns
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [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
示例7: get_mx_domains
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [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]
示例8: lookup_host
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [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
示例9: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def process(self, i, router):
if i.itype != 'fqdn':
return
if 'search' in i.tags:
return
try:
r = resolve_ns(i.indicator, t='CNAME')
except Timeout:
self.logger.info('timeout trying to resolve: {}'.format(i.indicator))
r = []
for rr in r:
# http://serverfault.com/questions/44618/is-a-wildcard-cname-dns-record-valid
rr = str(rr).rstrip('.').lstrip('*.')
if rr in ['', 'localhost', '0.0.0.0']:
continue
fqdn = Indicator(**i.__dict__())
fqdn.indicator = rr
fqdn.lasttime = arrow.utcnow()
try:
resolve_itype(fqdn.indicator)
except InvalidIndicator as e:
self.logger.error(fqdn)
self.logger.error(e)
return
fqdn.itype = 'fqdn'
fqdn.confidence = (fqdn.confidence - 1)
router.indicators_create(fqdn)
示例10: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def process(self, i, router):
if i.itype != 'fqdn':
return
if 'search' in i.tags:
return
try:
r = resolve_ns(i.indicator)
except Timeout:
self.logger.info('timeout trying to resolve: {}'.format(i.indicator))
return
for rr in r:
if str(rr).rstrip('.') in ["", 'localhost', '0.0.0.0']:
continue
ip = Indicator(**i.__dict__())
ip.indicator = str(rr)
ip.lasttime = arrow.utcnow()
try:
resolve_itype(ip.indicator)
except InvalidIndicator as e:
self.logger.error(ip)
self.logger.error(e)
else:
ip.itype = 'ipv4'
ip.rdata = i.indicator
ip.confidence = (ip.confidence - 4) if ip.confidence >= 4 else 0
router.indicators_create(ip)
示例11: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def process(self, i, router):
if i.itype != 'fqdn':
return
if 'search' in i.tags:
return
try:
r = resolve_ns(i.indicator, t='MX')
except Timeout:
self.logger.info('timeout trying to resolve MX for: {}'.format(i.indicator))
return
for rr in r:
rr = re.sub(r'^\d+ ', '', str(rr))
rr = str(rr).rstrip('.')
if rr in ["", 'localhost', '0.0.0.0']:
continue
fqdn = Indicator(**i.__dict__())
fqdn.indicator = rr.rstrip('.')
fqdn.lasttime = arrow.utcnow()
# 10
if re.match('^\d+$', rr):
return
try:
resolve_itype(fqdn.indicator)
except InvalidIndicator as e:
self.logger.info(fqdn)
self.logger.info(e)
else:
fqdn.itype = 'fqdn'
fqdn.rdata = i.indicator
fqdn.confidence = (fqdn.confidence - 5) if fqdn.confidence >= 5 else 0
router.indicators_create(fqdn)
示例12: process
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def process(self, i, router):
if i.itype != 'fqdn':
return
if 'search' in i.tags:
return
try:
r = resolve_ns(i.indicator)
except Timeout:
self.logger.info('timeout trying to resolve: {}'.format(i.indicator))
return
for rr in r:
rr = str(rr)
if rr in ["", 'localhost', '0.0.0.0']:
continue
ip = Indicator(**i.__dict__())
ip.lasttime = arrow.utcnow()
ip.indicator = rr
try:
resolve_itype(ip.indicator)
except InvalidIndicator as e:
self.logger.error(ip)
self.logger.error(e)
else:
ip.itype = 'ipv4'
ip.rdata = i.indicator
ip.confidence = (ip.confidence - 2) if ip.confidence >= 2 else 0
router.indicators_create(ip)
# also create a passive dns tag
ip.tags = 'pdns'
ip.confidence = 10
router.indicators_create(ip)
示例13: consumer
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def consumer(self):
while True:
try:
hostname, rtype = self.queue.get(True, 5)
except Empty:
logging.debug("Empty! Bailing")
return
try:
logging.debug("Starting work on {}".format(hostname))
results = self.resolver.query(hostname, rtype)
if results:
if hostname not in self.results:
self.results[hostname] = {}
text_results = []
for r in results:
if isinstance(r, NS_class):
text_results.append(r.target.to_text())
elif isinstance(r, A_class):
text_results.append(r.to_text())
else:
logging.error(
"Unknown record type: {}".format(type(r)))
hostname = Hostname(value=hostname)
ResolveHostnames.each(hostname, rtype, text_results)
except NoAnswer:
continue
except NXDOMAIN:
continue
except Timeout:
logging.debug("Request timed out for {}".format(hostname))
continue
except NoNameservers:
continue
except Exception as e:
import traceback
logging.error(
"Unknown error occurred while working on {} ({})".format(
hostname, rtype))
logging.error("\nERROR: {}".format(hostname, rtype, e))
logging.error(traceback.print_exc())
continue
示例14: gc_connect
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def gc_connect(self, protocol='ldap'):
"""
Connect to the global catalog
"""
if self.hostname in self.ad.gcs():
# This server is a Global Catalog
initial_server = self.hostname
else:
# Pick the first GC server
try:
initial_server = self.ad.gcs()[0]
except IndexError:
# TODO: implement fallback options for GC detection?
logging.error('Could not find a Global Catalog in this domain!'\
' Resolving will be unreliable in forests with multiple domains')
return False
try:
# Convert the hostname to an IP, this prevents ldap3 from doing it
# which doesn't use our custom nameservers
logging.info('Connecting to GC LDAP server: %s' % initial_server)
q = self.ad.dnsresolver.query(initial_server, tcp=self.ad.dns_tcp)
for r in q:
ip = r.address
except (resolver.NXDOMAIN, resolver.Timeout):
for server in self.ad.gcs():
# Skip the one we already tried
if server == initial_server:
continue
try:
# Convert the hostname to an IP, this prevents ldap3 from doing it
# which doesn't use our custom nameservers
logging.info('Connecting to GC LDAP server: %s' % server)
q = self.ad.dnsresolver.query(server, tcp=self.ad.dns_tcp)
for r in q:
ip = r.address
break
except (resolver.NXDOMAIN, resolver.Timeout):
continue
self.gcldap = self.ad.auth.getLDAPConnection(hostname=ip, gc=True,
baseDN=self.ad.baseDN, protocol=protocol)
return self.gcldap is not None
示例15: provider_from_address
# 需要导入模块: from dns import resolver [as 别名]
# 或者: from dns.resolver import Timeout [as 别名]
def provider_from_address(email_address, dns_resolver=_dns_resolver):
if not EMAIL_REGEX.match(email_address):
raise InvalidEmailAddressError('Invalid email address')
domain = email_address.split('@')[1].lower()
mx_domains = get_mx_domains(domain, dns_resolver)
ns_records = []
try:
ns_records = dns_resolver().query(domain, 'NS')
except NoNameservers:
log.error('NoNameservers', domain=domain)
except NXDOMAIN:
log.error('No such domain', domain=domain)
except Timeout:
log.error('Time out during resolution', domain=domain)
except NoAnswer:
log.error('No answer from provider', domain=domain)
for (name, info) in providers.iteritems():
provider_domains = info.get('domains', [])
# If domain is in the list of known domains for a provider,
# return the provider.
for d in provider_domains:
if domain.endswith(d):
return name
for (name, info) in providers.iteritems():
provider_mx = info.get('mx_servers', [])
# If a retrieved mx_domain is in the list of stored MX domains for a
# provider, return the provider.
if mx_match(mx_domains, provider_mx):
return name
for (name, info) in providers.iteritems():
provider_ns = info.get('ns_servers', [])
# If a retrieved name server is in the list of stored name servers for
# a provider, return the provider.
for rdata in ns_records:
if str(rdata).lower() in provider_ns:
return name
return 'unknown'
# From tornado.httputil