BF2Statistics.ASP.Ip2nation.GetCountryCode C# (CSharp) Метод

GetCountryCode() публичный статический Метод

Gets the country code for a string IP address
public static GetCountryCode ( IPAddress IP ) : string
IP System.Net.IPAddress
Результат string
        public static string GetCountryCode(IPAddress IP)
        {
            // Return default config Country Code
            if (IPAddress.IsLoopback(IP) || HttpServer.LocalIPs.Contains(IP))
                return Program.Config.ASP_LocalIpCountryCode;

            try
            {
                using (DatabaseDriver Driver = new DatabaseDriver(DatabaseEngine.Sqlite, ConnectionString))
                {
                    // Fetch country code from Ip2Nation
                    Driver.Connect();
                    List<Dictionary<string, object>> Rows = Driver.Query(
                        "SELECT country FROM ip2nation WHERE ip < @P0 ORDER BY ip DESC LIMIT 1",
                        Networking.IP2Long(IP.ToString())
                    );
                    string CC = (Rows.Count == 0) ? "xx" : Rows[0]["country"].ToString();

                    // Fix country!
                    return (CC == "xx" || CC == "01") ? Program.Config.ASP_LocalIpCountryCode : CC;
                }
            }
            catch
            {
                return Program.Config.ASP_LocalIpCountryCode;
            }
        }