Esempio n. 1
0
        /// <summary>
        /// 根据IP获取省市
        /// </summary>
        /// <param name="Type">类型 Type 1.返回省市   2.返回省市+区县</param>
        /// <returns></returns>
        public static string GetAddressByIp(string ip, int Type = 1)
        {
            string PostUrl = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=" + ip;
            string res     = GetDataByPost(PostUrl);//该条请求返回的数据为:res=1\t115.193.210.0\t115.194.201.255\t中国\t浙江\t杭州\t电信

            string[] arr = getAreaInfoList(res);

            string province = Province.GetProvince(arr[0]);
            string city     = Province.GetCity(arr[1]);

            if (string.IsNullOrEmpty(city))
            {
                city = Province.GetArea(arr[1]);
            }


            if (Type == 1)
            {
                return(province);
            }
            else
            {
                return(province + " " + (string.IsNullOrEmpty(city) ? arr[1] : city));
            }
        }