using MaxMind.GeoIP2; namespace Shared.Engine { public class GeoIP2 { static DatabaseReader cityReader = null, asnReader = null; static GeoIP2() { if (File.Exists("data/GeoLite2-Country.mmdb")) cityReader = new DatabaseReader("data/GeoLite2-Country.mmdb"); if (File.Exists("data/GeoLite2-ASN.mmdb")) asnReader = new DatabaseReader("data/GeoLite2-ASN.mmdb"); } /// IP пользователя /// Страна UA,RU,BY,KZ public static string Country(string IP) { if (string.IsNullOrEmpty(IP) || cityReader == null) return null; try { return cityReader.Country(IP).Country.IsoCode.ToUpper(); } catch { return null; } } /// IP пользователя /// ASN (например: 13335) public static long ASN(string IP) { if (string.IsNullOrEmpty(IP) || asnReader == null) return -1; try { return asnReader.Asn(IP).AutonomousSystemNumber ?? -1; } catch { return -1; } } } }