联系客服: iP138.com客服 iP138客服 |

iP查询接口
  • API接口QQ交流群:177096428   iP138 api接口
  • 数据修正QQ处理群:94181690    iP138数据修正

iP查询接口支持HTTPS(赠送1000次)

简介:获取iP地址对应的省市区以及运营商名称

已连接应用数:56343

国内:网宿cdn; 国际:亚洲中国香港、韩国首尔、日本东京、新加坡、欧洲德国法兰克福、北美洲美国硅谷节点

接口地址

http协议:
国内大陆优化(支持ipv6)http://api.ipshudi.com/ip/
国际各洲覆盖(部份ipv6)http://api.ip138.com/ip/

https协议:
国内大陆优化(支持ipv6)https://api.ipshudi.com/ip/
国际各洲覆盖(部份ipv6)https://api.ip138.com/ip/

* API接口可能会因为各种网络原因和攻击都可能产生阻断,请开发时做好冗余和异常处理

* 当HTTP请求返回的状态码非200时,请做异常处理,比如 202 状态码造成的原因可能是无效Token、余额不足、格式错误

Java调用iP查询接口示例:

                                    public class QueryHelper {

                                        /**
                                         * txt|jsonp|xml
                                         */
                                        public static String DATATYPE="text";
                                        
                                        public static String get(String urlString,String token) {
                                            try {
                                                URL url = new URL(urlString);
                                                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                                                conn.setConnectTimeout(5 * 1000);
                                                conn.setReadTimeout(5 * 1000);
                                                conn.setDoInput(true);
                                                conn.setDoOutput(true);
                                                conn.setUseCaches(false);
                                                conn.setInstanceFollowRedirects(false);
                                                conn.setRequestMethod("GET"); 
                                                conn.setRequestProperty("token",token);
                                                int responseCode = conn.getResponseCode();
                                                if (responseCode == 200) {
                                                    StringBuilder builder = new StringBuilder();
                                                    BufferedReader br = new BufferedReader(
                                                            new InputStreamReader(conn.getInputStream(),"utf-8"));
                                                    for (String s = br.readLine(); s != null; s = br
                                                            .readLine()) {
                                                        builder.append(s);
                                                    }
                                                    br.close();
                                                    return builder.toString();
                                                }
                                            } catch (IOException e) {
                                                e.printStackTrace();
                                            }
                                            return null;
                                        }
                                        public static String queryIP(String ip){
                                            String url="https://api.ip138.com/ip/?ip="+ip+"&datatype="+DATATYPE;
                                            String token="859476648b3de65d76804906dd1a1c6a";
                                            return get(url,token);
                                        }
                                    }

                                    //以下是使用示例:
                                    //QueryHelper.queryIP("8.8.8.8");