Example #1
0
def _get_ip_lookup_cache() -> IPLookupCache:
    """A file based fall-back DNS cache in case resolution fails"""
    if _config_cache.exists("ip_lookup"):
        # Return already created and initialized cache
        return cast(IPLookupCache, _config_cache.get("ip_lookup", IPLookupCache))

    cache = cast(IPLookupCache, _config_cache.get("ip_lookup", IPLookupCache))
    cache.load_persisted()
    return cache
Example #2
0
def _ip_to_hostname(config_cache, ip):
    # type: (config.ConfigCache, Optional[HostAddress]) -> Optional[HostName]
    if not _config_cache.exists("ip_to_hostname"):
        cache = _config_cache.get_dict("ip_to_hostname")

        for host in config_cache.all_active_realhosts():
            try:
                cache[ip_lookup.lookup_ipv4_address(host)] = host
            except Exception:
                pass
    else:
        cache = _config_cache.get_dict("ip_to_hostname")

    return cache.get(ip)