IP地址查询接口是指能够返回IP地址相关信息的网络接口,其返回的信息通常包括IP地址的归属地(如国家、省份、城市等)、运营商信息以及其他技术细节。以下是一些常见的IP地址查询接口及其特点:
一、国内IP地址查询接口
-
百度IP地址查询接口
- 接口地址:[无限免费]全球IP归属地查询_API专区_云市场-阿里云(指定IP查询)
- 请求方式:GET
- 参数:对于当前IP查询,无需参数;对于指定IP查询,需传入IP地址等参数。
- 返回结果:包括国家、省份、城市等信息。
- 具体信息
Java代码实现
java">//https://market.aliyun.com/apimarket/detail/cmapi00066996?spm=5176.730005.result.2.5ef9414ayVtSoP#sku=yuncode6099600002public static void main(String[] args) {String host = "https://kzipglobal.market.alicloudapi.com";String path = "/api/ip/query";String method = "POST";String appcode = "你自己的AppCode";Map<String, String> headers = new HashMap<String, String>();//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105headers.put("Authorization", "APPCODE " + appcode);//根据API的要求,定义相对应的Content-Typeheaders.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");Map<String, String> querys = new HashMap<String, String>();Map<String, String> bodys = new HashMap<String, String>();bodys.put("ip", "39.170.93.199");try {/*** 重要提示如下:* HttpUtils请从* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java* 下载** 相应的依赖请参照* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml*/HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);System.out.println(response.toString());//获取response的body//System.out.println(EntityUtils.toString(response.getEntity()));} catch (Exception e) {e.printStackTrace();}}
ip解析城市结果
{"msg": "成功","success": true,"code": 200,"data": {"orderNo": "202408040848319168904","nation": "中国","province": "浙江省", //省份"city": "杭州市", //城市"ip": "39.170.93.199", //本机ip"isp": "移动" //运营商}
}