|
|
|
@ -5,6 +5,8 @@ import org.lionsoul.ip2region.xdb.Searcher;
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
|
|
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
|
|
public class IpUtil {
|
|
|
|
|
private static final String IP2REGION_DB_FILE_PATH = "ip2region.xdb";
|
|
|
|
|
private static final String UNKNOW_IP = "未知IP";
|
|
|
|
@ -22,7 +24,11 @@ public class IpUtil {
|
|
|
|
|
|
|
|
|
|
public static String getIpLocation(String ip) {
|
|
|
|
|
try {
|
|
|
|
|
return searcher.search(ip).split("\\|")[2].replaceFirst("省", "");
|
|
|
|
|
String ipLocation = searcher.search(ip);
|
|
|
|
|
if (ipLocation.startsWith(Constants.IP_LOCATION_CHINA)) {
|
|
|
|
|
return ipLocation.split("\\|")[2].replaceFirst("省", "");
|
|
|
|
|
}
|
|
|
|
|
return ipLocation.split("\\|")[0];
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return UNKNOW_IP;
|
|
|
|
|
}
|
|
|
|
|