一切从登录记录开始

看到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#实现的更多相关文章

  1. 分享几个免费IP地址查询API接口

    几个免费IP地址查询API接口 1.IP地址查询接口:http://apis.juhe.cn/ip/ip2addr要先去https://www.juhe.cn/docs/api/...申请APPKEY ...

  2. 几个免费IP地址查询API接口

    转:http://blog.csdn.net/ishxiao/article/details/52670242 -------------------------------------------- ...

  3. API之IP地址查询---权威的IP地址查询接口集合

    原文地址:http://yushine.iteye.com/blog/1717586 推荐实用IP138 http://www.baidu.com/s?wd=IP&rsv_spt=1& ...

  4. [1]IP地址查询

    今天起开始玩百度APIStore里面的免费API.以前用过的有12306的:数据.接口,有时间整理出来,12306的有点乱就是了.还有扇贝以及有道的API,之前用在留言板里自动翻译,公司用过百度地图以 ...

  5. 齐全的IP地址查询接口及调用方法(转)

    设计蜂巢IP地址查询接口:http://www.hujuntao.com/api/ip/ip.php 腾讯IP地址查询接口:http://fw.qq.com/ipaddress 新浪IP地址查询接口: ...

  6. IP地址查询接口及调用方法

    1.查询地址 搜狐IP地址查询接口(IP):http://pv.sohu.com/cityjson 1616 IP地址查询接口(IP+地址):http://w.1616.net/chaxun/ipto ...

  7. IP地址查询接口

    新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:http://int.dpool. ...

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

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

  9. Android中由IP地址查询经纬度坐标的实例

    大家都知道,根据IP地址就可以知道它所在的具体位置,在Android中同样可以由IP地址得到它的位置,即具体的地理经纬度坐标. 本文就直接以代码的方式演示如何根据IP地址查询地理经纬度坐标位置,下面的 ...

随机推荐

  1. .net下BerkeleyDB操作封装C#版(附单元测试)

        using System; using System.Collections.Generic; using System.IO; using System.Linq; using System ...

  2. 在Windows下使用Nodist进行Node版本控制

    完全卸载Node.js 首先卸载Node.js应用程序 确认在C:\Program Files中没有Nodejs目录 确认在C:\Program Files (x86)没有Nodejs目录 删除C:\ ...

  3. AngularJS中的http拦截

    $http服务允许我们与服务端交互,有时候我们希望在发出请求之前以及收到响应之后做些事情.即http拦截. $httpProvider包含了一个interceptors的数组. 我们这样创建一个int ...

  4. 虚方法的调用是怎么实现的(单继承VS多继承)

    我们知道通过一个指向之类的父类指针可以调用子类的虚方法,因为子类的方法会覆盖父类同样的方法,通过这个指针可以找到对象实例的地址,通过实例的地址可以找到指向对应方法表的指针,而通过这个方法的名字就可以确 ...

  5. [转]java byte 数据类型(基础)

    package com.suypower.chengyu.test; public class ByteTest { /** * byte 8 bits -128 - + 127 * 1 bit = ...

  6. Hbase&Hadoop常用命令

    Hbase中根据Rowkey的前缀Prefix查询数据: scan 'test_xiaomifeng_monitoring_log',{FILTER => "(PrefixFilter ...

  7. [GraphQL] Write a GraphQL Schema in JavaScript

    Writing out a GraphQL Schema in the common GraphQL Language can work for simple GraphQL Schemas, but ...

  8. ios中将事件添加到系统日历

    - (void)saveEvent:(id)sender { //事件市场 EKEventStore *eventStore = [[EKEventStore alloc] init]; //6.0及 ...

  9. 可编辑的DIV -编辑器

    找了好多,没几个好用的,都或多或少有问题 目前这个最好用..  不过有一个奇葩的问题,就是要放在"<a></a>"标签里面, js或者jQuery获取  $ ...

  10. 开发常用到的terminal命令

    1.删除work_plugin目录下的.svn文件(最后面的;也是命令的一部分) sudo find /Users/maxinliang/DaTang/work_plugin ".svn&q ...