javascript通过ip获取物理地址接口

2018-10-12更新:新浪的IP地址接口已经失效

可以使用百度的IP地址解析接口:https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=117.140.170.110&ie=utf8&resource_id=6006&cb=callback

cb为jsonp回掉名称,query为要查询的ip地址,返回jsonp数据格式如下

/**/callback({"status":"0","t":"","set_cache_time":"","data":[{"location":"广西壮族自治区玉林市 移动","titlecont":"IP地址查询","origip":"117.140.170.110","origipquery":"117.140.170.110","showlamp":"1","showLikeShare":1,"shareImage":1,"ExtendedLocation":"","OriginQuery":"117.140.170.110","tplt":"ip","resourceid":"6006","fetchkey":"117.140.170.110","appinfo":"","role_id":0,"disp_type":0}]});

  

javascript如何通过访问者ip地址获取ip地址对应的物理地址API接口

新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js,返回数据结构如下

var remote_ip_info = {"ret":1,"start":"116.1.29.0","end":"116.1.43.255","country":"\u4e2d\u56fd","province":"\u5e7f\u897f","city":"\u6842\u6797","district":"\u4e03\u661f","isp":"\u7535\u4fe1","type":"","desc":""};

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

var remote_ip_info = {"ret":1,"start":"218.192.0.0","end":"218.192.7.255","country":"\u4e2d\u56fd","province":"\u5e7f\u4e1c","city":"\u5e7f\u5dde","district":"","isp":"\u6559\u80b2\u7f51","type":"\u5b66\u6821","desc":"\u5e7f\u5dde\u5927\u5b66\u7eba\u7ec7\u670d\u88c5\u5b66\u9662"};

搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson

var returnCitySN = {"cip": "116.1.39.88", "cid": "450300", "cname": "广西壮族自治区桂林市"};

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

var returnCitySN = {"cip": "116.1.39.88", "cid": "450300", "cname": "广西壮族自治区桂林市"};

号称是google的,验证了可以用,只是返回的是函数,不是JSON结构。http://j.maxmind.com/app/geoip.js

function geoip_country_code() { return 'CN'; }
function geoip_country_name() { return 'China'; }
function geoip_city()         { return 'Guilin'; }
function geoip_region()       { return '16'; }
function geoip_region_name()  { return 'Guangxi'; }
function geoip_latitude()     { return '25.2819'; }
function geoip_longitude()    { return '110.2864'; }
function geoip_postal_code()  { return ''; }
function geoip_area_code()    { return ''; }
function geoip_metro_code()   { return ''; }

示例,搜狐API

<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8" charset="utf-8"></script>
<script type="text/javascript">
    window.onload = function () {
        document.body.appendChild(document.createTextNode('['+returnCitySN.cname+"]的朋友,您好!"));
    }
</script>

 


原创文章,转载请注明出处:javascript通过ip获取物理地址接口

评论(0)Web开发网
阅读(1767)喜欢(0)JavaScript/Ajax开发技巧