zoukankan      html  css  js  c++  java
  • 通过IP得到IP所在地省市

    /// <summary>         
            /// 通过IP得到IP所在地省市(Porschev)         
            /// </summary>         
            /// <param name="ip"></param>         
            /// <returns></returns>         
            private string GetAddressByIP(string ip)
            {
                string res = String.Empty;
                string url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" + ip;
    
                HttpItem item = new HttpItem
                {
                    Url = url,
                    Method = "POST",
                    Accept = "application/json",
                    ContentType = "application/x-www-form-urlencoded"
                };
    
                //得到请求结果
                string result = helper.GetHtml(item).Html;
                result = ConvertUnicode2Chinese(result);
    
                JObject obj = (JObject)result.JsonToObject();
                if (obj != null)
                {
                    //{ "ret":1,"start":"115.28.0.0","end":"115.29.255.255","country":"中国","province":"北京","city":"北京","district":"","isp":"电信","type":"机房","desc":"中国万网机房电信"}
    
                    res = obj["province"].ToString() + obj["city"].ToString();
                }
                return res;
            }
    
            /// <summary>
            /// 将Unicode编码转换成中文
            /// </summary>
            /// <param name="result"></param>
            /// <returns></returns>
            private string ConvertUnicode2Chinese(string result)
            {
                Regex reg = new Regex(@"(?i)\[uU]([0-9a-f]{4})");
                return reg.Replace(result, delegate(Match m)
                {
                    return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString();
                });
            }
    

      

  • 相关阅读:
    jsop
    对象冒充call
    php中的static
    PHP对象在内存堆栈中的分配
    递归
    php简单日历
    php分页类
    请写一个函数,实现以下功能: 字符串“open_door” 转换成 “OpenDoor”、”make_by_id” 转换成 ”MakeById”
    php 计算两个文件之间的相对路径方法
    php冒泡排序
  • 原文地址:https://www.cnblogs.com/zhao-yi/p/8059795.html
Copyright © 2011-2022 走看看