ip地址查询城市

public bool IsExitCityByIP(string ip,out string city)
         {            
                string[] ips = ip.Split('.');
                 double ipNum = Convert.ToDouble(ips[0]) * 16777216 + Convert.ToDouble(ips[1]) * 65536 + Convert.ToDouble(ips[2]) * 256 + Convert.ToDouble(ips[3]);
 
                string[] cityName = { "Shenzhen", "Shanghai", "Guangzhou", "Hong Kong" };
                 IPGroupCity c = GetAddressByIPNum(ipNum);
                 city = c.City.ToString();
                 if (city != null)计算
                 {
                     for (int i = 0; i < cityName.Length; i++)
                     {
                         if (cityName[i].Equals(city))
                         {
                             lblAddress.Text = "您查询的IP:" + txtIP.Text + "<br>IP地址位置:" + c.Country_name + "--" + city;
                             return true;
                         }
                         else if (cityName[i].Equals(c.Country_name))
                         {
                             lblAddress.Text = "您查询的IP:" + txtIP.Text + "<br>IP地址位置:" + c.Country_name + "--" + city;
                             return true;
                         }
                     }
                     lblAddress.Text = "您查询的IP:" + txtIP.Text + "<br>IP地址位置:" + c.Country_name + "--" + city + "!   您没有在OpenRice所涉足的五个城市内 ";
                     return false;
                 }
                 else
                 {
                     ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('您输入的IP没有相关记录')", true);  
                     return false;
                 }
                  
        }

 

posted @ 2013-07-30 15:02  Token007  阅读(602)  评论(0编辑  收藏  举报