Пример #1
0
        static CityResponse GeoLocate_GetCity(System.Net.IPAddress ipaddress)
        {
            using (var mm = new MaxMind.GeoIP2.DatabaseReader(GEOLOCATION_CITY_DB_FILE))
            {
                var responce = mm.City(ipaddress);

                return(responce);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="IP">IP пользователя</param>
        /// <returns>Страна/Город/Регион</returns>
        public static (string Country, string City, string Region) City(string IP)
        {
            string Country = "Unknown", City = "Unknown", Region = "Unknown";

            try
            {
                using (var reader = new MaxMind.GeoIP2.DatabaseReader(Folders.Databases + "/GeoLite2-City.mmdb"))
                {
                    var response = reader.City(IP);
                    City    = string.IsNullOrEmpty(response.City.Name) ? "Unknown" : response.City.Name;
                    Country = string.IsNullOrEmpty(response.Country.Name) ? "Unknown" : response.Country.Name;
                    Region  = string.IsNullOrEmpty(response.MostSpecificSubdivision.Name) ? "Unknown" : response.MostSpecificSubdivision.Name;
                }
            }
            catch { }

            return(Country, City, Region);
        }
Пример #3
0
        public override string[] IsMatch(WorkspaceResult result, string fragment, Stream stream)
        {
            const string HostIPCacheKey = "hostip";

            try
            {
                var uri = new Uri(result.RequestProperties["uri"]);

                if (!result.PropertyCache.ContainsKey(HostIPCacheKey))
                {
                    result.PropertyCache.Add(HostIPCacheKey, Utility.GetHostIPAddress(uri).GetAwaiter().GetResult());
                }

                IPAddress ip = result.PropertyCache[HostIPCacheKey] as IPAddress;

                var c = database.City(ip);

                return(GetTags(c).Where(x => !string.IsNullOrWhiteSpace(x) && (string.IsNullOrWhiteSpace(FilterData) || x.Contains(FilterData))).ToArray());
            }
            catch (AddressNotFoundException ex)
            {
                return(EmptySet);
            }
        }
Пример #4
0
        private string City(string ip)
        {
            if (string.IsNullOrWhiteSpace(ip) || ip.Equals("127.0.0.1")) return string.Empty;

            var db = new MaxMind.GeoIP2.DatabaseReader(Server.MapPath("/App_Data/GeoLite2-City.mmdb"));
            
            try{
                var city = db.City(ip);
                return city.City.Name;
            }
            catch{
                return string.Empty;
            }
        }