ip地址查询城市代码

19 篇文章 0 订阅
5 篇文章 0 订阅

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;
                }
                
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值