import java.io.File;
import java.net.InetAddress;
import com.fasterxml.jackson.databind.JsonNode;
import com.maxmind.db.Reader;
public class IpDemo {
public static void main(String[] args) throws Exception {
File database = new File("resources/Country.mmdb");
Reader reader = new Reader(database);
// 查询
InetAddress address = InetAddress.getByName("114.114.114.114");
JsonNode response = reader.get(address);
System.out.println(response);
reader.close();
}
}
需要引入 Maxmind DB
和 Jackson Databind
包
pom.xml
:
<project>
<!-- .. -->
<properties>
<!-- .. -->
<maxmind.version>1.2.1</maxmind.version>
<jackson.version>2.16.1</jackson.version>
</properties>
<dependencies>
<!-- .. -->
<dependency>
<groupId>com.maxmind.db</groupId>
<artifactId>maxmind-db</artifactId>
<version>${maxmind.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
</project>
标签:jackson,MMDB,数据库,Reader,查询,import,maxmind,com From: https://www.cnblogs.com/Undefined443/p/18020883