private static void HandleDNSReq(string msg, Tunnel tunnel) { if (!string.IsNullOrEmpty(msg) && tunnel != null) { string[] args = msg.Split(' '); if (args.Length >= 2) { string domain = args[1]; IPAddress ip; if (dnsCaches.ContainsKey(domain)) { if (!dnsCaches[domain].IsDead) { ip = dnsCaches[domain].IP; } else { ip = ResolvDNS(domain); if (ip != null) { dnsCaches[domain].IP = ip; } } } else { ip = ResolvDNS(domain); if (ip != null) { DnsCache cache = new DnsCache(domain, ip, Conf.DnsCacheTtl); dnsCaches.TryAdd(cache.Domain, cache); } } string reply; if (ip == null) { reply = "nok"; } else { reply = ip.ToString(); } tunnel.WriteL(reply); } } }
private static void SendDNSReq(EagleTunnelArgs e) { if (e != null) { if (e.Domain != null) { if (Conf.hosts.ContainsKey(e.Domain)) { e.IP = Conf.hosts[e.Domain]; e.Success = true; } else { if (EagleTunnelHandler.dnsCaches.ContainsKey(e.Domain)) { if (!EagleTunnelHandler.dnsCaches[e.Domain].IsDead) { e.IP = EagleTunnelHandler.dnsCaches[e.Domain].IP; e.Success = true; } else { if (ResolvDomain(e)) { EagleTunnelHandler.dnsCaches[e.Domain].IP = e.IP; e.Success = true; } } } else { if (ResolvDomain(e)) { DnsCache cache = new DnsCache(e.Domain, e.IP, Conf.DnsCacheTtl); EagleTunnelHandler.dnsCaches.TryAdd(e.Domain, cache); e.Success = true; } } } } } }