说明 “在线版SDK”仅供“在线API”使用;“离线版SDK”请“登录阿里云控制台-云解析DNS-IP地理位置库-实例详情”下载。

目前阿里云官方提供的SDK分6种语言版本,Java、Python、PHP,GO,C++,C#具体链接如下:

更多语言版本的SDK,您可以前往阿里云IP地理位置库SDK服务中进行选择。

相关信息:关于AccessKey的获取

SDK安装

SDK安装您可以通过添加maven库或者jar包依赖安装SDK,本文以Java语言为示例。

  • 添加maven库
<repositories>
        <repository>
            <id>sonatype-nexus-staging</id>
            <name>Sonatype Nexus Staging</name>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
</repositories>
  • 添加jar包依赖
<dependency>    
    <groupId>com.aliyun</groupId>    
    <artifactId>aliyun-java-sdk-geoip</artifactId>    
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.4.9</version>
</dependency>

示例代码

public class DescribeIpv4Location {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        DescribeIpv4LocationRequest request = new DescribeIpv4LocationRequest();
        request.setIp("221.206.131.10");
        try {
            DescribeIpv4LocationResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}