简介
ip2region 是准确率99.9%的ip地址定位库,0.0x毫秒级查询,数据库文件大小只有1.5M,提供了java,php,c,python,nodejs,golang,c#查询绑定和Binary,B树,内存三种查询算法!
maven依赖
org.lionsoul
ip2region
1.7.2
下载这个项目之后到data/文件夹下面找到ip2region.db,我放在了/user/home目录下
Java 工具类
public class IpUtil {
public static String getCityInfo(String ip, int type) {
//db
String dbPath = "/usr/home/ip2region.db";
File file = new File(dbPath);
if (!file.exists()) {
return "Error: Invalid ip2region.db file";
}
// 查询算法
// DbSearcher.BTREE_ALGORITHM B-tree
// DbSearcher.BINARY_ALGORITHM Binary
// DbSearcher.MEMORY_ALGORITYM Memory
// int algorithm = DbSearcher.BINARY_ALGORITHM;
try {
DbConfig config = new DbConfig();
DbSearcher se