免费ip归属地查询api接口

1. ip-api.com ,可切换显示语言

请求格式如图:
http://ip-api.com/json/117.136.12.79?lang=zh-CN
返回格式如图:

 {
      "status": "success",
      "country": "中国",
      "countryCode": "CN",
      "region": "GD",
      "regionName": "广东",
      "city": "广州市",
      "zip": "",
      "lat": 23.1181,
      "lon": 113.2539,
      "timezone": "Asia/Shanghai",
      "isp": "China Mobile communications corporation",
      "org": "China Mobile",
      "as": "AS56040 China Mobile communications corporation",
      "query": "117.136.12.79"
  }

2. 百度

http://opendata.baidu.com/api.php?query=117.136.12.79&co=&resource_id=6006&oe=utf8

返回如图:

{
    "status": "0",
    "t": "",
    "set_cache_time": "",
    "data": [
        {
            "location": "广东省广州市 移动",
            "titlecont": "IP地址查询",
            "origip": "117.136.12.79",
            "origipquery": "117.136.12.79",
            "showlamp": "1",
            "showLikeShare": 1,
            "shareImage": 1,
            "ExtendedLocation": "",
            "OriginQuery": "117.136.12.79",
            "tplt": "ip",
            "resourceid": "6006",
            "fetchkey": "117.136.12.79",
            "appinfo": "",
            "role_id": 0,
            "disp_type": 0
        }
    ]
}

3. 太平洋

http://whois.pconline.com.cn/ipJson.jsp?ip=117.136.12.79&json=true

{
    "ip": "117.136.12.79",
    "pro": "广东省",
    "proCode": "440000",
    "city": "佛山市",
    "cityCode": "440600",
    "region": "",
    "regionCode": "0",
    "addr": "广东省佛山市 移动",
    "regionNames": "",
    "err": ""
}
  1. 126
    http://ip.ws.126.net/ipquery?ip=117.136.12.79

    var lo="广东省", lc="";
    var localAddress=

封装方法如下(百度api):

/*
 * 通过ip获取归属地
 *
 * */
function getIpAddress($ip=''){
    if(empty($ip)){
        return '请输入IP地址';
    }
    $res = @file_get_contents('http://opendata.baidu.com/api.php?query='.$ip.'&co=&resource_id=6006&oe=utf8');
    $result = json_decode($res,true);
    if(empty($result['data'])){
        return false;
    }
    return $result['data'];
}

参考博客:https://blog.csdn.net/weixin_29053561/article/details/111996442

posted @ 2021-04-07 15:59  八戒vs  阅读(1549)  评论(0编辑  收藏  举报