• 网易及新浪IP查询接口


    通过IP地址获取对应的地区信息通常有两种方法:
    1)自己写程序,解析IP对应的地区信息,需要数据库。
    2)根据第三方提供的API查询获取地区信息。

    第一种方法,参见文本《通过纯真IP数据库获取IP地址对应的地区信息》,这种方法的维护代价较高,而且对自己的服务器有一定的压力。

    随着技术的开放,第三方已经逐渐免费开放相应的API。经过测试,目前网易和新浪提供的较为稳定易用。

    1)新浪IP地址查询API接口

    新浪的IP地址查询接口:

    http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=IP地址

    测试用例:

    http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=114.114.114.114

    返回以下信息:

    var remote_ip_info = {"ret":1,"start":"114.114.112.0","end":"114.114.119.255","country":"u4e2du56fd","province":"u6c5fu82cf","city":"u5357u4eac","district":"","isp":"u7535u4fe1","type":"","desc":"u5357u4eacu4fe1u98ce114dnsu4e13u5c5e"};

    文字经过utf-8编码,分别对应不同的信息。
    可以通过javascript跨域直接调用,如(使用jquery):

    $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='+ip, function(_result){  

    if (remote_ip_info.ret == '1'){   

    alert('IP 详细信息:', 'IP:'+ip+'<BR>国 家:'+remote_ip_info.country+'<BR>省 份:'+remote_ip_info.province+'<BR>城 市:'+remote_ip_info.city+'<BR> 区:'+remote_ip_info.district+'<BR>ISP:'+remote_ip_info.isp+'<BR> 类型:'+remote_ip_info.type+'<BR>其他:'+remote_ip_info.desc);   

    } else {   

    alert('错误', '没有找到匹配的 IP 地址信息!');   

    }  

    2)网易有道IP地址API接口

    查询IP地址:

    http://www.youdao.com/smartresult-xml/search.s?type=ip&q=IP地址

    举例:

    http://www.youdao.com/smartresult-xml/search.s?type=ip&q=114.114.114.114

    返回xml文本信息:

    <?xml version="1.0" encoding="gbk"?>

    <smartresult>

    <product type="ip">

    <ip>114.114.114.114</ip>

    <location>江苏省南京市 信风网络科技有限公司公众DNS服务器</location>

    </product>

    </smartresult>

    ================

    一般情况下可以用到判断ip跳转,比如不同区域侦测到ip后进行跳转到不同页面或者ip日志记录。如下:我是通过ip判断跳转到不同页面,可以让不同ip看到不同东西。

    html代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
        
    <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" charset="utf-8" ></script>
    <script type="text/javascript" charset="GB2312">
    <!--document.write(remote_ip_info.province);document.write(remote_ip_info.isp);  显示区域,已屏蔽,实现无痕跳转-->
    var pro=remote_ip_info.province;
    
    if(pro='河南'){
            window.location.href="index.php";
    }else {
            window.location.href="http://www.victdo.com/index/index.html";
    }
    </script>
    
    </head>
    
    <body>
    </body>
    </html>
    
  • 相关阅读:
    nginx 配置文件配置
    源码编译php5.4 ./configure参数
    腾讯云Linux VPS新硬盘分区与挂载教程(面板重装不丢失数据)
    十行代码带你量化交易入门
    谱聚类(转)
    随机模拟(MCMC)
    LDA 线性判别分析
    Windows10上安装Keras 和 TensorFlow-GPU
    ASCII 码
    KL距离,Kullback-Leibler Divergence
  • 原文地址:https://www.cnblogs.com/netsa/p/5728002.html
Copyright © 2020-2023  润新知