<script src="http://counter.sina.com.cn/ip" type="text/javascript" charset=gb2312></script> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script type="text/javascript" charset=gb2312> var sf=ILData[2]; if(sf.indexOf("北京")>=0 || sf.indexOf("上海")>=0 || sf.indexOf("保留")>=0 ){
<!-- IP STOP START --> <script src="http://counter.sina.com.cn/ip" type="text/javascript" charset=gb2312></script> <script type="text/javascript" charset="gb2312"> var sf=ILData[1]; var sf2=ILData[2]; if(sf.indexOf("上海")>=0 || sf2.indexOf("上海")>=0 || sf.indexOf("保留")>=0 ){ window.location.href="/404.html"; } </script> <!-- IP OVER -->
1、淘宝IP地址库 http://ip.taobao.com/
*. 请求接口(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址]
*. 返回数据格式:(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商。例如:
{"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317", "region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1", "country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000", "county_id":"-1","isp_id":"100017"}}
注:其中code的值的含义为,0:成功,1:失败。
*. 淘宝IP接口使用示例PHP版:
<?php $ip=get_ip_data(); function get_ip_data(){ $ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip()); $ip = json_decode($ip); if($ip->code){ return false; } $data = (array) $ip->data; print_r($data);//return $data; } //取客户端 ip function get_client_ip(){ if (isset($_SERVER['HTTP_CLIENT_IP']) and !empty($_SERVER['HTTP_CLIENT_IP'])){ return $_SERVER['HTTP_CLIENT_IP']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ return strtok($_SERVER['HTTP_X_FORWARDED_FOR'], ','); } if (isset($_SERVER['HTTP_PROXY_USER']) and !empty($_SERVER['HTTP_PROXY_USER'])){ return $_SERVER['HTTP_PROXY_USER']; } if (isset($_SERVER['REMOTE_ADDR']) and !empty($_SERVER['REMOTE_ADDR'])){ return $_SERVER['REMOTE_ADDR']; } else { return "0.0.0.0"; } } ?>
2、搜狐IP地址查询接口(默认编码GBK):http://pv.sohu.com/cityjson?ie=utf-8
3、新浪IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=[ip地址]
注:参数format可设置返回格式:js/json;参数ip可选查询IP;
*. 返回格式如下:
var remote_ip_info = {"ret":1,"start":"125.40.0.0","end":"125.40.111.255","country":"\u4e2d\u56fd","province":"\u6cb3\u5357","city":"\u90d1\u5dde","district":"","isp":"\u8054\u901a","type":"","desc":""};
下面的实例用到了JQuery下的getScript()方法:
<div id="sina_ip_info"></div> <script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var uip = '125.40.0.0'; $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='+uip, function(_result){ var ipData = ""; //初始化保存内容变量 if (remote_ip_info.ret == '1'){ ipData += "IP 详细信息:<br>"; ipData += "IP:" + uip + "<br>"; ipData += "国家:" + remote_ip_info.country + "<br>"; ipData += "省份:" + remote_ip_info.province + "<br>"; ipData += "城市:" + remote_ip_info.city + "<br>"; ipData += "区:" + remote_ip_info.district + "<br>"; ipData += "ISP:" + remote_ip_info.isp + "<br>"; ipData += "类型:" + remote_ip_info.type + "<br>"; ipData += "其他:" + remote_ip_info.desc + "<br>"; $("#sina_ip_info").html(ipData); //显示处理后的数据 } else { alert('错误', '没有找到匹配的 IP 地址信息!'); } }); </script>