获取Ip 的地域等信息的API

网上查到有以下结果

淘宝的IP接口地址: http://ip.taobao.com/instructions.php 
腾讯的IP地址API接口地址:http://fw.qq.com/ipaddress 
新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 
新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42 
搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson 
搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8 
搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip 

目前我用的是:https://pv.sohu.com/cityjson?ie=utf-8
简易demo,新建index.html文件,代码如下:


<html>
<head>
  <title>title>
head>
<body>
  <script type="text/javascript" src="https://pv.sohu.com/cityjson?ie=utf-8">script>
  <script type="text/javascript">
    var city=returnCitySN,UserLocation,UserIP;
    UserLocation=city.cname;//地域名
    UserIP=city.cip;//IP
    document.write(UserLocation);
    document.write("
"
); document.write(UserIP);
script> body> html>

你可能感兴趣的:(JavaScript日常处理)