IpUtil { public static String getCityInfo(String ip) { if (!Util.isIpAddress(ip)) { return null; } if ("127.0.0.1".equals(ip) || "0.0.0.0".equals(ip)) { return "beijing"; } try { DbConfig config = new DbConfig(); String dbFilePath = IpUtil.class.getResource("/ip2region.db").getPath(); DbSearcher searcher = new DbSearcher(config, dbFilePath); DataBlock block = searcher.binarySearch(ip); return block.getRegion(); } catch (DbMakerConfigException | IOException e) { logger.error("ip2region, error: [{}]", e); return null; } } private  IpUtil(); static String getIpAddress(HttpServletRequest request); static String getCityInfo(String ip);  }
@Test public void getCityInfo() throws Exception { String ip = "1.119.195.242"; String res = IpUtil.getCityInfo(ip); System.out.println("getCityInfo result : " + res); }