JS实现获取IP地址及地理信息

1. 搜狐IP地址查询接口(可设置编码)javascript

<html>
<head>
<meta charset="utf-8">
<title>使用搜狐接口获取客户端IP地址</title>
</head>
<body>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
document.write(returnCitySN["cip"]+','+returnCitySN["cname"])
</script>
</body>
</html>php

二、新浪提供接口,经过网络IP查看城市信息html

<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>java

var city = remote_ip_info['city'];json

3.太平洋IP地址库API接口微信

比较全面的API:http://whois.pconline.com.cn/?ip=0.0.0.0#tabs-3网络

<HTML>
<HEAD>
<TITLE>GetLocalIP</TITLE>
</HEAD>
<BODY>
您的位置信息是:<span id="idTestJson"></span><br/>
<script>
function testJson(obj) {
    document.getElementById("idTestJson").innerHTML = "ip["+obj.ip+"]省["+obj.pro+"] 市["+obj.city+"] 区["+obj.region+"]";
}
</script>
<script src="http://whois.pconline.com.cn/ipJson.jsp?callback=testJson"></script>
</BODY>
</HTML>jsp

4.  国外freegeoip.net ,IP地址查询接口编码

$.getJSON("http://freegeoip.net/json/",
    function(obj){
        alert(obj.city+" "+obj.country_code+" "+obj.ip);
)spa

若有BUG或者须要jar包,加我微信!

相关文章
相关标签/搜索