Ejemplo n.º 1
0
        public static void Add(DnsMessage dnsMessage, HttpContext context)
        {
            if (dnsMessage.AnswerRecords.Count <= 0)
            {
                return;
            }
            var dnsRecordBase = dnsMessage.AnswerRecords.FirstOrDefault();

            if (RealIP.TryGetFromDns(dnsMessage, out var ipAddress))
            {
                Add(new CacheItem(
                        $"DNS:{GeoIP.GetGeoStr(ipAddress)}{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                        new CacheEntity
                {
                    List        = dnsMessage.AnswerRecords.ToList(),
                    Time        = DateTime.Now,
                    ExpiresTime = DateTime.Now.AddSeconds(dnsRecordBase.TimeToLive)
                }),
                    dnsRecordBase.TimeToLive);
            }
            else
            {
                Add(new CacheItem($"DNS:{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                                  new CacheEntity
                {
                    List        = dnsMessage.AnswerRecords.ToList(),
                    Time        = DateTime.Now,
                    ExpiresTime = DateTime.Now.AddSeconds(dnsRecordBase.TimeToLive)
                }),
                    dnsRecordBase.TimeToLive);
            }
        }
Ejemplo n.º 2
0
        public static void Add(DnsMessage dnsMessage, HttpContext context)
        {
            if (dnsMessage.AnswerRecords.Count <= 0)
            {
                return;
            }
            var dnsRecordBase = dnsMessage.AnswerRecords.FirstOrDefault();

            if (RealIP.TryGetFromDns(dnsMessage, out var ipAddress))
            {
                Add(new CacheItem(
                        $"{GeoIP.GetGeoStr(ipAddress)}:{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                        dnsMessage.AnswerRecords.ToList()), dnsRecordBase.TimeToLive);
            }
            else
            {
                Add(new CacheItem($"{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                                  dnsMessage.AnswerRecords.ToList()), dnsRecordBase.TimeToLive);
            }
        }
Ejemplo n.º 3
0
        public static void Add(DnsMessage dnsMessage, HttpContext context)
        {
            foreach (var item in new List <DnsRecordBase>(dnsMessage.AnswerRecords).Where(item =>
                                                                                          (item.Name.IsSubDomainOf(DomainName.Parse("arashi-msg")) ||
                                                                                           item.Name.IsSubDomainOf(DomainName.Parse("nova-msg"))) && item.RecordType == RecordType.Txt))
            {
                dnsMessage.AnswerRecords.Remove(item);
            }

            if (dnsMessage.AnswerRecords.Count <= 0)
            {
                return;
            }
            var dnsRecordBase = dnsMessage.AnswerRecords.FirstOrDefault();

            if (RealIP.TryGetFromDns(dnsMessage, out var ipAddress))
            {
                Add(new CacheItem(
                        $"DNS:{GeoIP.GetGeoStr(ipAddress)}{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                        new CacheEntity
                {
                    List        = dnsMessage.AnswerRecords.ToList(),
                    Time        = DateTime.Now,
                    ExpiresTime = DateTime.Now.AddSeconds(dnsRecordBase.TimeToLive)
                }),
                    dnsRecordBase.TimeToLive);
            }
            else
            {
                Add(new CacheItem($"DNS:{dnsRecordBase.Name}:{dnsRecordBase.RecordType}",
                                  new CacheEntity
                {
                    List        = dnsMessage.AnswerRecords.ToList(),
                    Time        = DateTime.Now,
                    ExpiresTime = DateTime.Now.AddSeconds(dnsRecordBase.TimeToLive)
                }),
                    dnsRecordBase.TimeToLive);
            }
        }