コード例 #1
0
ファイル: Util.cs プロジェクト: Officeclip/devmon_agent
        public static string GetIpInfo(string ipAddress, bool isCountry)
        {
            var      cityName    = string.Empty;
            var      countryName = string.Empty;
            IPResult ipResult    = new IP2Location.IPResult();

            try
            {
                if (!string.IsNullOrEmpty(ipAddress))
                {
                    var ip2Component = new IP2Location.Component();
                    ip2Component.IPDatabasePath =
                        System.IO.Path.GetFullPath(
                            HostingEnvironment.MapPath(
                                "~/App_Data/IP2LOCATION-LITE-DB3.BIN"));
                    //"C:\\officeclipnew\\opensource\\devmon_agent\\dev_web_api\\App_Data\\IP2LOCATION-LITE-DB3.BIN";
                    ipResult = ip2Component.IPQuery(ipAddress);
                    switch (ipResult.Status.ToString())
                    {
                    case "OK":
                        cityName    = ipResult.City;
                        countryName = ipResult.CountryShort;
                        break;

                    case "EMPTY_IP_ADDRESS":
                        throw new Exception("IP Address cannot be blank.");

                    case "INVALID_IP_ADDRESS":
                        throw new Exception("Invalid IP Address.");

                    case "MISSING_FILE":
                        throw new Exception("Invalid Database Path.");
                    }
                }
                else
                {
                    return("Unknown");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                ipResult = null;
            }

            return(isCountry == true ? countryName : cityName);
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: Officeclip/devmon_agent
        /// <summary>
        /// Retunrn the Full country name like United States of America
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        public static string GetIpFullInfo(string ipAddress)
        {
            var      cityName    = string.Empty;
            var      countryName = string.Empty;
            IPResult ipResult    = new IP2Location.IPResult();

            try
            {
                if (ipAddress != "" && ipAddress != null)
                {
                    var ip2Component = new IP2Location.Component();
                    ip2Component.IPDatabasePath =
                        System.IO.Path.GetFullPath(
                            HostingEnvironment.MapPath(
                                "~/App_Data/IP2LOCATION-LITE-DB3.BIN"));
                    ipResult = ip2Component.IPQuery(ipAddress);
                    switch (ipResult.Status.ToString())
                    {
                    case "OK":
                        cityName    = ipResult.City;
                        countryName = ipResult.CountryLong;
                        break;

                    case "EMPTY_IP_ADDRESS":
                        throw new Exception("IP Address cannot be blank.");

                    case "INVALID_IP_ADDRESS":
                        throw new Exception("Invalid IP Address.");

                    case "MISSING_FILE":
                        throw new Exception("Invalid Database Path.");
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                ipResult = null;
            }
            return(countryName);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: azhard4int/crawlers
        public string Location(string IP)
        {
            IP2Location.Component oIP2Location = new IP2Location.Component();
            IPResult oIPResult = new IP2Location.IPResult();
            string status = null;
            try
            {
                if (IP != "")
                {
                    oIP2Location.IPDatabasePath = @"E://IP2LOCATION-LITE-DB1.BIN";
                    oIPResult = oIP2Location.IPQuery(IP);
                    switch (oIPResult.Status.ToString())
                    {
                        case "OK":
                            status = oIPResult.CountryLong.ToString();
                            break;
                        case "EMPTY_IP_ADDRESS":
                            status = "IP Address cannot be blank.";
                            break;
                        case "INVALID_IP_ADDRESS":
                            status = "Invalid IP Address.";
                            break;
                        case "MISSING_FILE":
                            status = "Invalid Database Path.";
                            break;
                    }

                }
                else
                {
                    return "IP Address cannot be blank.";
                }

                return status;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                oIPResult = null;
            }
        }