/// <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();
});
}

  

通过IP得到IP所在地省市的更多相关文章

  1. 根据IP地址查询所在地

    using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Tex ...

  2. python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码

    python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码 淘宝IP地址库 http://ip.taobao.com/目前提供的服务包括:1. 根据用户提供的 ...

  3. 通过IP获取对应所在地的地址

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangshuxuncom/article/details/35988143         曾几何时 ...

  4. 百度接口通过ip获取用户所在地

    /** * 百度接口      * 通过用户ip获取用户所在地      * @param userIp      * @return      */ public static String get ...

  5. PHP获取客户端操作系统,浏览器,语言,IP,IP归属地等

    <?php class Client { ////获得访客浏览器类型 function Get_Browser(){ if(!empty($_SERVER['HTTP_USER_AGENT']) ...

  6. 几种获取IP 根据IP获取地址的方法 JS,第三方 新浪 网易 腾讯

    第一种是利用纯真ip数据库,这个可以在网上找到很多,缺点是更新有点慢. 第二种是利用门户网站的接口 目前已知的有腾讯.新浪.网易.搜狐和Google提供IP地址查询API,但是找得到的只有腾讯.新浪和 ...

  7. Windows Azure Virtual Network (7) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (2)

    <Windows Azure Platform 系列文章目录> 本文介绍的是,当用户在创建Azure Virtual Machine的时候,忘记绑定公网IP,需要重新绑定公网IP的具体操作 ...

  8. 彻底明白IP地址——IP地址的介绍

    彻底明白IP地址——IP地址的介绍 [ 作者:担子    转贴自:赛迪网    点击数:9692    更新时间:2004-12-22  ]   IP地址的介绍 1.IP地址的表示方法 IP地址 = ...

  9. Web Performance Test : IP切换/IP欺骗

    译者前言 本文翻译自<Visual Studio Performance Testing Quick Reference Guide 3.6> 有关于IP Switching的章节.< ...

随机推荐

  1. Python服务器开发 -- 网络基础

    Python服务器开发 -- 网络基础   网络由下往上分为物理层.数据链路层.网络层.传输层.会话层.表示层和应用层.HTTP是高层协议,而TCP/IP是个协议集,包过许多的子协议.... 网络由下 ...

  2. Java中通过Array.sort()对数组从大到小排序

    package com.itheimajavase; import java.util.Arrays; import java.util.Comparator; public class Day01 ...

  3. java获取一段字符串里符合日期的正则表达式的字符串

    import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test3 { public static v ...

  4. [Luogu] 八数码难题

    https://www.luogu.org/problemnew/show/P1379 long long ago 暴力bfs #include <iostream> #include & ...

  5. DRF-解析器组件源码解析

    解析器组件源码解析 解析器组件源码解析 1 执行request.data 开始找重装的request中的data方法 2 在dispatch找到重装的request def dispatch(self ...

  6. sequence_loss的解释

    在做seq2seq的时候,经常需要使用sequence_loss这是损失函数. 现在分析一下sequence_loss这个函数到底在做什么 # coding: utf-8 import numpy a ...

  7. 从 s 点到 t 点的最短路(简单模板)(迪杰斯特拉)

    迪杰斯特拉简单版 #include <bits/stdc++.h> using namespace std; int m,n; const int inf = 0x3f3f3f3f; in ...

  8. scss的使用

    看到一篇很好的文章,感觉不用我自己总结了, 上个链接:https://blog.csdn.net/zhouzuoluo/article/details/81010331

  9. 八十年代的经典 NFS和AFS

    NFS:(C/S模式) 大体架构: 1985年Sun公司基于UDP开发了网络共享文件系统(Network FileSystem) NFS由一系列NFS命令和进程组成的客户机/服务器模式,在第三版中加入 ...

  10. 应用fluent二维单向流泥沙冲刷作用下河床变形代码【转载】

    本代码转载自:http://www.codeforge.cn/read/260028/keti_2d_b.c__html #include "udf.h" #define Rho ...