Beispiel #1
0
        /// <summary>
        /// @nation:国家,@province:省,@city市,@county:县,默认@province|@city
        /// </summary>
        ///
        public static string IPLocation(string ip, string tlp, bool getisp)
        {
            if (string.IsNullOrEmpty(ip))
            {
                return("无IP信息");
            }
            if (ip.Equals("::1"))
            {
                return("本地主机");
            }
            IPAddress ipadr = null;

            if (!IPAddress.TryParse(ip, out ipadr))
            {
                return("无效IP");
            }
            IPCity cityMod = FindCity(ip);

            if (!string.IsNullOrEmpty(cityMod.City))
            {
                cityMod.City += "市 ";
            }
            string result = "";

            if (cityMod.Province.Equals("局域网"))
            {
                result = cityMod.Province;
            }
            else
            {
                result = tlp.Replace("@nation", cityMod.Nation)
                         .Replace("@province", cityMod.Province)
                         .Replace("@city", cityMod.City)
                         .Replace("@county", cityMod.County);
            }
            if (getisp)
            {
                try
                {
                    string isp = ISPScaner.GetIpISP(ip);
                    if (!string.IsNullOrEmpty(isp))
                    {
                        result += "(" + isp + ")";
                    }
                }
                catch { result += "(未知)"; }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 根据IP地址获取其运营商信息
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static string GetIpISP(string ip)
        {
            ISPScaner isp = new ISPScaner();

            return(isp.SearchIPLocation(ip).Area);
        }