Beispiel #1
0
        public static DnsMessage DnsQuery(DnsMessage dnsMessage, HttpContext context,
                                          bool CnDns = true, bool Cache = true)
        {
            try
            {
                if (Config.CacheEnable && !context.Request.Query.ContainsKey("no-cache") && Cache)
                {
                    if (Config.GeoCacheEnable && DnsCache.Contains(dnsMessage, context))
                    {
                        return(DnsCache.Get(dnsMessage, context));
                    }
                    if (DnsCache.Contains(dnsMessage))
                    {
                        return(DnsCache.Get(dnsMessage));
                    }
                }

                if (Config.ChinaListEnable && !context.Request.Query.ContainsKey("no-cndns") && CnDns &&
                    DNSChina.IsChinaName(dnsMessage.Questions.FirstOrDefault().Name) &&
                    dnsMessage.Questions.FirstOrDefault().RecordType == RecordType.A)
                {
                    return(DNSChina.ResolveOverChinaDns(dnsMessage));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(DnsQuery(UpEndPoint.Address, dnsMessage, UpEndPoint.Port, Config.TimeOut) ??
                   DnsQuery(BackUpEndPoint.Address, dnsMessage, BackUpEndPoint.Port, Config.TimeOut));
        }
Beispiel #2
0
        public static DnsMessage DnsQuery(DnsMessage dnsMessage, HttpContext context = null)
        {
            try
            {
                if (Config.CacheEnable)
                {
                    if (context != null && Config.GeoCacheEnable && DnsCache.Contains(dnsMessage, context))
                    {
                        return(DnsCache.Get(dnsMessage, context));
                    }
                    if (DnsCache.Contains(dnsMessage))
                    {
                        return(DnsCache.Get(dnsMessage));
                    }
                }

                if (Config.ChinaListEnable && DNSChina.IsChinaName(dnsMessage.Questions.FirstOrDefault().Name) &&
                    dnsMessage.Questions.FirstOrDefault().RecordType == RecordType.A)
                {
                    return(DNSChina.ResolveOverHttpDns(dnsMessage));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(DnsQuery(Config.UpStream, dnsMessage));
        }