IP地址查询API的C#实现
一切从登录记录开始
看到TX的登录记录之后,突然想去在登录环节也加上这个功能,然后就写了下面的具体实现代码。现在一点也不纠结IP在数据库中保存类型是UNSIGNED INT还是VARCHAR了。
干货来了哦_
using System.Net;
using System.Web;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
namespace ConsoleApplication1
{
public class IPToLocation
{
public IPLocation GetLocationByTB(string ip)
{
if (string.IsNullOrEmpty(ip))
return null;
var webClient = new WebClient();
var entity = webClient.DownloadString(string.Format("http://ip.taobao.com/service/getIpInfo.php?ip={0}",ip));
var json = new JavaScriptSerializer().Deserialize<dynamic>(entity);
if (json == null || json["code"] == 1)
return GetLocationBySina(ip); //调用其它接口
var data = new JavaScriptSerializer().Serialize(json["data"]);
IPLocation model = JsonConvert.DeserializeObject<IPLocation>(data);
return model;
}
public IPLocation GetLocationBySina(string ip)
{
// http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip={0}
// 其它同上哦.
}
}
[JsonObject]
public class IPLocation
{
[JsonProperty]
public string IP { get; set; }
[JsonProperty]
public string Country { get; set; }
[JsonProperty]
public string Country_Id { get; set; }
[JsonProperty]
public string Area { get; set; }
[JsonProperty]
...
...
}
}
IP地址查询API的C#实现的更多相关文章
- 分享几个免费IP地址查询API接口
几个免费IP地址查询API接口 1.IP地址查询接口:http://apis.juhe.cn/ip/ip2addr要先去https://www.juhe.cn/docs/api/...申请APPKEY ...
- 几个免费IP地址查询API接口
转:http://blog.csdn.net/ishxiao/article/details/52670242 -------------------------------------------- ...
- API之IP地址查询---权威的IP地址查询接口集合
原文地址:http://yushine.iteye.com/blog/1717586 推荐实用IP138 http://www.baidu.com/s?wd=IP&rsv_spt=1& ...
- [1]IP地址查询
今天起开始玩百度APIStore里面的免费API.以前用过的有12306的:数据.接口,有时间整理出来,12306的有点乱就是了.还有扇贝以及有道的API,之前用在留言板里自动翻译,公司用过百度地图以 ...
- 齐全的IP地址查询接口及调用方法(转)
设计蜂巢IP地址查询接口:http://www.hujuntao.com/api/ip/ip.php 腾讯IP地址查询接口:http://fw.qq.com/ipaddress 新浪IP地址查询接口: ...
- IP地址查询接口及调用方法
1.查询地址 搜狐IP地址查询接口(IP):http://pv.sohu.com/cityjson 1616 IP地址查询接口(IP+地址):http://w.1616.net/chaxun/ipto ...
- IP地址查询接口
新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:http://int.dpool. ...
- 根据IP地址查询所在地
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Tex ...
- Android中由IP地址查询经纬度坐标的实例
大家都知道,根据IP地址就可以知道它所在的具体位置,在Android中同样可以由IP地址得到它的位置,即具体的地理经纬度坐标. 本文就直接以代码的方式演示如何根据IP地址查询地理经纬度坐标位置,下面的 ...
随机推荐
- Advanced Puppet 系列的前言
什么是Advanced 在网络上,你能找到大量关于Puppet的安装,配置以及基础用法的文章和博客.你在通过一段时间的实战后,熟练掌握了Puppet基础用法,随着你管理的集群日益扩大,你的部署逻辑越来 ...
- old header
海纳百川 山不拒土 No Backspace in Real Life. Love Life![Cloud][LBS][GIS][GPS][MAPS][C++][Java]
- Undokumentierte @Formeln/LotusScript im Lotus Notes Client/Server
Erstellung von Replik-IDs mittels @Text-Funktion@Text( @Now; "*" )Source NoPersist option ...
- nodejs+express+jade安装备忘
安装步骤 1.安装nodejs,比如安装在E:\nodejs. 确保有两个环境变量 用户环境变量:C:\Users\Administrator\AppData\Roaming\npm 系统环境变量:e ...
- 一个批量移除BOM头的bash脚本
有时候我们的文件可能不需要BOM头,例如:我们公司的SVN服务器提供的代码都UTF8编码保存(不能有BOM头)否则代码提交不上去. 文件很多的时候就需要批量操作. 脚本使用方法:remove-bom. ...
- windows 2003服务器网络异常流量的处理办法
最近通过防火墙发现一台服务器的流量占用非常厉害,上传的流量每秒达到100—200Mb/s,几乎占掉了一半的带宽.本来那台服务器上安装了360安全卫士,360安全卫士自身带的网络防火墙只能看进程,而不能 ...
- UICollectionView瀑布流的实现原理(转)
http://ios.jobbole.com/85689/ 和使用 UIScollView 创刊一个瀑布流是一样的方式 7cc829d3gw1f4nq2oc09zj20j00hvq90.jpg 我的 ...
- iOS WKWebView详解
UIWebView就不用说了,这个过时了,现在iOS8以后建议都使用WKWebView. WKWebView 是现代 WebKit API 在 iOS 8 和 OS X Yosemite 应用中的核心 ...
- Python中的模块与包
标准库的安装路径 在import模块的时候,python是通过系统路径找到这些模块的,我们可以将这些路径打印出来: >>> pprint.pprint(sys.path) ['', ...
- 【python】日志模块
# -*- coding: utf-8 -*- """ Created on Thu Jul 09 09:36:59 2015 @author: dapenghuang ...