美文网首页
使用js获取客户端IP地址及省份城市

使用js获取客户端IP地址及省份城市

作者: JuanitaLee | 来源:发表于2018-11-13 18:29 被阅读15次

查询访问网站用户的IP,网上查询了资料挺多的,不过有些已经失效了。

1、搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson
2、搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8

接口返回的是一个JS数组,比如这样:
var returnCitySN = {"cip": "119.130.228.18", "cid": "440100", "cname": "广东省广州市"};
使用方法实例代码:

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script language="JavaScript">
    var clientIP = returnCitySN["cip"];
    alert(clientIP);
</script>

3、搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip

4、新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js

5、新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42

6、腾讯的接口:http://fw.qq.com/ipaddress (腾讯,pconline 的API已经失效 不能使用 )

相关文章

网友评论

      本文标题:使用js获取客户端IP地址及省份城市

      本文链接:https://www.haomeiwen.com/subject/saglfqtx.html