C#获取主机的物理IP地址(city level)。
发布时间
阅读量:
阅读量
经过查阅大量相关途径后,最终选择了淘宝api方法,问题得以成功解决!
第一步:需要使用 Newtonsoft.Json;
引入该框架时,需先获取 Newtonsoft.Json.zip 文件
具体下载链接如下:http://www.zhating.cn/index.php/post/90.html
第二步:将文件解压到 dug 文件夹中,然后右键点击解决方案,选择添加-引用-浏览,找到并双击添加 Newtonsoft.Json.dll(关于如何引用该 dll 文件,可参考 http://www.zhating.cn/index.php/post/66.html )
完成以上操作后,继续添加以下代码
第三步:核心代码如下:
public static string GetIPCitys(string strIP)
{
try
{
string Url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + strIP + "";
System.Net.WebRequest wReq = System.Net.WebRequest.Cre
全部评论 (0)
还没有任何评论哟~
