예제 #1
0
        public static string GetClientCoutry()
        {
            //OperationContext context = OperationContext.Current;
            //System.ServiceModel.Channels.MessageProperties prop = context.IncomingMessageProperties;
            //System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint =
            //prop[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
            //string ip = endpoint.Address;
            string retIp = "";

            OperationContext context = OperationContext.Current;

            MessageProperties prop = context.IncomingMessageProperties;

            HttpRequestMessageProperty endpointLoadBalancer =
                prop[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

            if (endpointLoadBalancer.Headers["X-Forwarded-For"] != null)
            {
                retIp = endpointLoadBalancer.Headers["X-Forwarded-For"];
            }

            if (string.IsNullOrEmpty(retIp))
            {
                RemoteEndpointMessageProperty endpoint =
                    prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                retIp = endpoint.Address;
            }

            string filePath = ConfigurationManager.AppSettings["countryFilePath"];

            CountryLookup cl = new CountryLookup(filePath);

            return(cl.lookupCountryCode(retIp));
        }
예제 #2
0
        public static bool IsVodEnabledForThisIP(string ip)
        {
            bool geoCheck = false;
            bool isParsed = bool.TryParse(ConfigurationManager.AppSettings["GeoCheck"], out geoCheck);

            string    notGeoCustomer     = ConfigurationManager.AppSettings["NotGeoCustomer"];
            ArrayList notGeoCustomerList = new ArrayList();

            notGeoCustomerList.AddRange(notGeoCustomer.Split(new char[] { ',' }));
            //
            string    geoCountries     = ConfigurationManager.AppSettings["GeoCountries"];
            ArrayList geoCountriesList = new ArrayList();

            geoCountriesList.AddRange(geoCountries.Split(new char[] { ',' }));
            //
            string filePath = ConfigurationManager.AppSettings["countryFilePath"];

            CountryLookup cl      = new CountryLookup(filePath);
            string        ooutput = cl.lookupCountryCode(ip);

            if (!geoCountries.Contains(ooutput))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
    public static string GetCountry(string ipAddress)
    {
        try {
            HttpContext   c  = HttpContext.Current;
            CountryLookup cl = new CountryLookup(c.Server.MapPath("~/GeoIpDB/GeoIP.dat"));

            object userCountry = c.Cache["country-" + ipAddress];
            if (userCountry == null)
            {
                userCountry = cl.lookupCountryCode(ipAddress);

                // add Cache
                c.Cache.Add("country-" + ipAddress, userCountry,
                            null,
                            TimeZoneManager.DateTimeNow.AddDays(3),
                            System.Web.Caching.Cache.NoSlidingExpiration,
                            System.Web.Caching.CacheItemPriority.Normal,
                            null);
            }



            return(userCountry.ToString());
        } catch {
            return(null);
        }
    }
예제 #4
0
        public static string GetClientCoutry()
        {
            //OperationContext context = OperationContext.Current;
            //System.ServiceModel.Channels.MessageProperties prop = context.IncomingMessageProperties;
            //System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint =
            //prop[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
            OperationContext  context = OperationContext.Current;
            MessageProperties prop    = context.IncomingMessageProperties;

            string ipaddress = "";
            HttpRequestMessageProperty endpointLoadBalancer = prop[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;


            //if (endpointLoadBalancer.Headers["X-Forwarded-For"] != null)
            //{
            //string headerkljucevi = string.Empty;
            //foreach (string hdr in endpointLoadBalancer.Headers)
            //{
            //    headerkljucevi += hdr + ",";
            //}
            //Utilities.InsertMobileLog(0, "GetIP 0", headerkljucevi, 1);

            ipaddress = endpointLoadBalancer.Headers["X-Forwarded-For"];
            Utilities.InsertMobileLog(0, "GetIP X-Forwarded-For ", ipaddress, 1);
            //}

            if (string.IsNullOrEmpty(ipaddress))
            {
                ipaddress = ipaddress = endpointLoadBalancer.Headers["X-Real-IP"];;
                Utilities.InsertMobileLog(0, "GetIP X-Real-IP ", ipaddress, 1);
            }
            //string ip = endpoint.Address;

            string filePath = ConfigurationManager.AppSettings["countryFilePath"];

            CountryLookup cl = new CountryLookup(filePath);

            return(cl.lookupCountryCode(ipaddress));
        }
예제 #5
0
파일: MineData.cs 프로젝트: e2tox/topbit
        private static void InsertOrUpdateAddress(string name, string address, CountryLookup lookup)
        {
            var record = Mine.FindOne(Restrictions.Eq("Name", name)) ?? new Mine {
                Name = name
            };

            record.Address = address;
            var uri  = new Uri(record.Address);
            var host = Dns.GetHostEntry(uri.DnsSafeHost);

            //update the country flag for the mine pools
            if (host.AddressList.Length > 0)
            {
                var ip          = host.AddressList[0];
                var countryCode = lookup.lookupCountryCode(ip);
                record.Icon     = "/Content/flags/" + countryCode + ".gif";
                record.IconName = lookup.lookupCountryName(ip);
            }
            record.IsOnline      = true;
            record.CheckTime     = DateTime.Now;
            record.NextCheckTime = DateTime.Now;
            record.Save();
        }