利用sina接口获取指定ip所在地区

<!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>Untitled Document</title>
<style type="text/css">
<!--
.btn{
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 12px;
 color: #666666;
 text-align: left;
 text-decoration: none;
 display: block;
 overflow: visible;
 margin-right: 10px;
 margin-left: 10px;
}
.btn a:hover {
 background-color: #d8dfea;
 border-top-width: 1px;
 border-bottom-width: 1px;
 border-top-style: solid;
 border-bottom-style: solid;
 border-top-color: #333366;
 border-bottom-color: #333366;
}
.btn a {
 display: block;
 text-decoration: none;
 color: #666666;
 border-top-width: 1px;
 border-bottom-width: 1px;
 border-top-style: solid;
 border-bottom-style: solid;
 border-top-color: #CCCCCC;
 border-bottom-color: #CCCCCC;
 width: 100px;
 padding-top: 5px;
 padding-right: 10px;
 padding-bottom: 5px;
 padding-left: 30px;
 overflow: visible;
 float: left;
}
html {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 12px;
 color: #333333;
 line-height: 18px;
 margin: 0px;
}
-->
body{
 margin:0px;
}
</style>
</head>
<body>
<p>
 <textarea name="source" rows="14" id="source" style="width:99%"></textarea>
</p>
<div class="btn"> <a href="javascript:action('CONVERT_FMT1')"> <strong>Convert</strong><br />
 Fmort &#xxxx </a></div>
<div class="btn"> <a href="javascript:action('CONVERT_FMT2')"> <strong>Convert</strong><br />
 Fmort \uxxxx </a> </div>
<div class="btn"> <a href="javascript:action('RECONVERT')"> <strong>ReConvert</strong><br />
 To 汉字 </a> </div>
<p>
<div id="tt" style="display:none"></div>
<textarea name="show2" rows="14" id="show2" style="width:99%"></textarea>
</p>
</body>
</html>
<script language="javascript" type="text/javascript">
var oSource = document.getElementById("source");
var oShow2 = document.getElementById("show2");
var oTt = document.getElementById("tt");
function action(pChoice){
 switch(pChoice){
  case "CONVERT_FMT1":
   oShow2.value = ascii(oSource.value);
   break;
  case "CONVERT_FMT2":
   oShow2.value = unicode(oSource.value);
   break;
  case "RECONVERT":
   oShow2.value = reconvert(oSource.value);
   break;
 }
}
function ascii(str){
 return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\&#x$2;")});
}
function unicode(str){
 return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function reconvert(str){ 
 str = str.replace(/(\\u)(\w{4})/gi,function($0){
            return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g,"$2")),16)));
            });
            
 str = str.replace(/(&#x)(\w{4});/gi,function($0){
            return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16));
            });            
 return str;
}
</script>



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

根据返回结果利用上面转码方式获取中文


其他接口:

http://pv.sohu.com/cityjson?ie=utf-8

http://pv.sohu.com/cityjson

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值