Exemplo n.º 1
0
 def _getaddrinfo(*args, **kwargs):
     global _dnscaache
     if args in _dnscaache:
         return _dnscaache[args]
     else:
         _dnscaache[args] = socket._getaddrinfo(*args, **kwargs)
         return _dnscaache[args]
Exemplo n.º 2
0
 def _fast_getaddrinfo(host, *args, **kwargs):
     def needs_dns_resolving(host2):
         try:
             ipaddress.ip_address(host2)
             return False  # already valid IP
         except ValueError:
             pass  # not an IP
         if str(host) in ('localhost', 'localhost.',):
             return False
         return True
     try:
         if needs_dns_resolving(host):
             answers = dns.resolver.query(host)
             addr = str(answers[0])
         else:
             addr = host
     except dns.exception.DNSException as e:
         # dns failed for some reason, e.g. dns.resolver.NXDOMAIN
         # this is normal. Simply report back failure:
         raise socket.gaierror(11001, 'getaddrinfo failed') from e
     except BaseException as e:
         # Possibly internal error in dnspython :( see #4483
         # Fall back to original socket.getaddrinfo to resolve dns.
         print_error('dnspython failed to resolve dns with error:', e)
         addr = host
     return socket._getaddrinfo(addr, *args, **kwargs)
Exemplo n.º 3
0
    def _fast_getaddrinfo(host, *args, **kwargs):
        def needs_dns_resolving(host2):
            try:
                ipaddress.ip_address(host2)
                return False  # already valid IP
            except ValueError:
                pass  # not an IP
            if str(host) in (
                    'localhost',
                    'localhost.',
            ):
                return False
            return True

        try:
            if needs_dns_resolving(host):
                answers = dns.resolver.query(host)
                addr = str(answers[0])
            else:
                addr = host
        except dns.exception.DNSException as e:
            # dns failed for some reason, e.g. dns.resolver.NXDOMAIN
            # this is normal. Simply report back failure:
            raise socket.gaierror(11001, 'getaddrinfo failed') from e
        except BaseException as e:
            # Possibly internal error in dnspython :( see #4483
            # Fall back to original socket.getaddrinfo to resolve dns.
            print_error('dnspython failed to resolve dns with error:', e)
            addr = host
        return socket._getaddrinfo(addr, *args, **kwargs)
Exemplo n.º 4
0
def _fast_getaddrinfo(host, *args, **kwargs):
    def needs_dns_resolving(host):
        try:
            ipaddress.ip_address(host)
            return False  # already valid IP
        except ValueError:
            pass  # not an IP
        if _is_force_system_dns_for_host(host):
            return False
        return True

    def resolve_with_dnspython(host):
        addrs = []
        expected_errors = (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer,
                           concurrent.futures.CancelledError,
                           concurrent.futures.TimeoutError)
        ipv6_fut = _dns_threads_executor.submit(dns.resolver.resolve, host,
                                                dns.rdatatype.AAAA)
        ipv4_fut = _dns_threads_executor.submit(dns.resolver.resolve, host,
                                                dns.rdatatype.A)
        # try IPv6
        try:
            answers = ipv6_fut.result()
            addrs += [str(answer) for answer in answers]
        except expected_errors as e:
            pass
        except BaseException as e:
            _logger.info(
                f'dnspython failed to resolve dns (AAAA) for {repr(host)} with error: {repr(e)}'
            )
        # try IPv4
        try:
            answers = ipv4_fut.result()
            addrs += [str(answer) for answer in answers]
        except expected_errors as e:
            # dns failed for some reason, e.g. dns.resolver.NXDOMAIN this is normal.
            # Simply report back failure; except if we already have some results.
            if not addrs:
                raise socket.gaierror(11001, 'getaddrinfo failed') from e
        except BaseException as e:
            # Possibly internal error in dnspython :( see #4483 and #5638
            _logger.info(
                f'dnspython failed to resolve dns (A) for {repr(host)} with error: {repr(e)}'
            )
        if addrs:
            return addrs
        # Fall back to original socket.getaddrinfo to resolve dns.
        return [host]

    addrs = [host]
    if needs_dns_resolving(host):
        addrs = resolve_with_dnspython(host)
    list_of_list_of_socketinfos = [
        socket._getaddrinfo(addr, *args, **kwargs) for addr in addrs
    ]
    list_of_socketinfos = [
        item for lst in list_of_list_of_socketinfos for item in lst
    ]
    return list_of_socketinfos
Exemplo n.º 5
0
 def _getaddrinfo(*args, **kwargs):
     if args in _dnscache:
         # print('使用了dns缓存:%s' % _dnscache[args])
         return _dnscache[args]
     else:
         _dnscache[args] = socket._getaddrinfo(*args, **kwargs)
         # print('添加dns缓存:%s' % _dnscache[args])
         return _dnscache[args]
Exemplo n.º 6
0
 def _getaddrinfo(*args, **kwargs):
     global _dnscache
     if args in _dnscache:  #如果dns缓冲中有
         return _dnscache[args]  #则返回缓存中的ip
     else:  #如果没有
         _dnscache[args] = socket._getaddrinfo(*args,
                                               **kwargs)  #进行dns查询并将结果放入缓存中
         return _dnscache[args]
Exemplo n.º 7
0
 def _getaddrinfo(*args, **kwargs):
     if args in _dnscache:
         # print str(args) + " in cache"
         return _dnscache[args]
     else:
         # print str(args) + " not in cache"
         _dnscache[args] = socket._getaddrinfo(*args, **kwargs)
         return _dnscache[args]
Exemplo n.º 8
0
def _caching_getaddrinfo(*args, **kwargs):
    try:
        query = (args)
        res = _dns_cache[query]
        return res
    except KeyError:
        res = socket._getaddrinfo(*args, **kwargs)
        _dns_cache[args] = res
        return res
Exemplo n.º 9
0
 def _getaddrinfo(*args, **kwargs):
         global _dnscache
         if args in _dnscache:
             print str(args) + " in cache"
             return _dnscache[args]
         else:
             print str(args) + " not in cache"
             _dnscache[args] = socket._getaddrinfo(*args, **kwargs)
             return _dnscache[args]
Exemplo n.º 10
0
    def _getaddrinfo(*args, **kwargs):
        if args in dns_cache:
            LOGGER.debug(f'Use dns cache {args}:{dns_cache[args]}')
            return dns_cache[args]

        else:
            LOGGER.debug(f'Without dns cache {args}')
            dns_cache[args] = socket._getaddrinfo(*args, **kwargs)
            return dns_cache[args]
Exemplo n.º 11
0
    def _getaddrinfo(*args, **kwargs):
        global _dnscache
        if args in _dnscache:
            # print(str(args) + " in cache")
            return _dnscache[args]

        else:
            # print(str(args) + " not in cache")
            _dnscache[args] = socket._getaddrinfo(*args, **kwargs)
            return _dnscache[args]
Exemplo n.º 12
0
 def _getaddrinfo(*args, **kwargs):
     self.m_dns_cache_mutex.acquire()
     dns_info = None 
     if args in self.m_dnscache:
         dns_info = self.m_dnscache[args]
     else:
         dns_info = socket._getaddrinfo(*args, **kwargs)
     self.m_dnscache[args] = dns_info 
     self.m_dns_cache_mutex.release()
     return dns_info 
Exemplo n.º 13
0
 def fast_getaddrinfo(host, *args, **kwargs):
     try:
         if str(host) not in ('localhost', 'localhost.',):
             answers = dns.resolver.query(host)
             addr = str(answers[0])
         else:
             addr = host
     except:
         raise socket.gaierror(11001, 'getaddrinfo failed')
     else:
         return socket._getaddrinfo(addr, *args, **kwargs)
Exemplo n.º 14
0
 def fast_getaddrinfo(host, *args, **kwargs):
     try:
         if str(host) not in ('localhost', 'localhost.',):
             answers = dns.resolver.query(host)
             addr = str(answers[0])
         else:
             addr = host
     except:
         raise socket.gaierror(11001, 'getaddrinfo failed')
     else:
         return socket._getaddrinfo(addr, *args, **kwargs)
Exemplo n.º 15
0
 def _caching_getaddrinfo(*args, **kwargs):
     try:
         query = (args)
         res = _dns_cache[query]
         #This was too noisy and not so usefull
         om.out.debug('Cached DNS response for domain: ' + query[0] )
         return res
     except KeyError:
         res = socket._getaddrinfo(*args, **kwargs)
         _dns_cache[args] = res
         om.out.debug('DNS response from DNS server for domain: ' + query[0] )
         return res
Exemplo n.º 16
0
 def _caching_getaddrinfo(*args, **kwargs):
     try:
         query = (args)
         res = _dns_cache[query]
         #This was too noisy and not so useful
         #om.out.debug('Cached DNS response for domain: ' + query[0] )
         return res
     except KeyError:
         res = socket._getaddrinfo(*args, **kwargs)
         _dns_cache[args] = res
         om.out.debug('DNS response from DNS server for domain: ' +
                      query[0])
         return res
Exemplo n.º 17
0
 def _getaddrinfo(*args, **kwargs):
     # print
     global _dnscache
     if args in _dnscache:
         # print args, " in cache", _dnscache[args]
         return _dnscache[args]
     else:
         _dnscache.setdefault(args, [])
         # print args, "not in cache"
         addrinfo_list = get_addrinfo(*args[:1])
         if not addrinfo_list:
             _dnscache[args] = socket._getaddrinfo(*args, **kwargs)
             return _dnscache[args]
         for i in addrinfo_list:
             addrinfo = (2, 1, 0, '', (i, args[1]))
             # print args, "add address:", addrinfo
             _dnscache[args].append(addrinfo)
         if file_name:
             with file(file_name, "a")as f:
                 dns_setting = i + " " + args[0] + "\n"
                 f.write(dns_setting)
         return _dnscache[args]
Exemplo n.º 18
0
def _getaddrinfo(*args, **kwargs):
  if args[0] in _dnscache:
    return _dnscache[args[0]]
  else:
    _dnscache[args[0]] = socket._getaddrinfo(*args, **kwargs)
    return _dnscache[args[0]]
Exemplo n.º 19
0
 def getaddrinfo(host, port, *args, **kwargs):
     if _is_force_system_dns_for_host(host):
         return socket._getaddrinfo(host, port, *args, **kwargs)
     return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (host, port))]
Exemplo n.º 20
0
 def _getaddrinfo(*args, **kwargs):
     if args in self._dnscache:
         return self._dnscache[args]
     else:
         self._dnscache[args] = socket._getaddrinfo(*args, **kwargs)
         return self._dnscache[args]