final Country country = countryResponse.getCountry(); final Map<Object, Object> map = new HashMap<>(); map.put("continent", countryResponse.getContinent());
CountryResponse response = reader.country(InetAddress.getByName(rp.getRemoteAddr())); Country country = response.getCountry(); rp.setRemoteAddrLocale(new Locale("", country.getIsoCode())); } catch (AddressNotFoundException e) {
public Optional<Country> getCountry(String ipAddress) { if (reader != null) { try { CountryResponse country = reader.country(InetAddress.getByName(ipAddress)); if (country != null) return Optional.of(country.getCountry()); } catch (AddressNotFoundException | UnknownHostException ex) { LOGGER.debug("Error geo-locating country.", ex); } catch (Exception ex) { LOGGER.error("Error geo-locating country.", ex); } } return Optional.empty(); } }
/** * Retrieves the country in full length (e.g. United States) from the IP Address. * <p> * This product includes GeoLite2 data created by MaxMind, available from * <a href="http://www.maxmind.com">http://www.maxmind.com</a>. * * @param ipAddress The IP Address from which the country is retrieved * @return The name of the country in full length. * <p> * An exception from that rule is when the country is unknown or the retrieval of the country failed in any way, * if that happens, "Not Known" will be returned. * @see <a href="http://maxmind.com">http://maxmind.com</a> * @see #getCountry(String) */ private String getUnCachedCountry(String ipAddress) { if ("127.0.0.1".equals(ipAddress)) { return "Local Machine"; } try { checkDB(); try (DatabaseReader reader = new DatabaseReader.Builder(geolocationDB).build()) { InetAddress inetAddress = InetAddress.getByName(ipAddress); CountryResponse response = reader.country(inetAddress); Country country = response.getCountry(); return country.getName(); } } catch (IOException | GeoIp2Exception e) { return "Not Known"; } }
throw event.buildException("Country not found for " + ipInfo.toString()); country = response.getCountry(); continent = response.getContinent(); registred_country = response.getRegisteredCountry();
private Map<String, Object> ip2SpatialData(InetAddress ip) { if (!enabled) { return null; } if (reader == null) { LOG.warn("Location database is not initialized. Exiting."); return null; } try { Map<String, Object> holder = new HashMap<>(3); if (dbType == LocationDatabaseType.COUNTRY) { Country country = reader.country(ip).getCountry(); holder.put(ObjectEsParameterFactory.GEOLOC_COUNTRY_CODE.getName(), country.getIsoCode()); } else { CityResponse city = reader.city(ip); Location loc = city.getLocation(); holder.put(ObjectEsParameterFactory.GEOLOC_COUNTRY_CODE.getName(), city.getCountry().getIsoCode()); holder.put(ObjectEsParameterFactory.GEOLOC_CITY_NAME.getName(), city.getCity().getName()); holder.put(ObjectEsParameterFactory.GEOLOC_GEO_POINT.getName(), new GeoPoint(loc.getLatitude(), loc.getLongitude())); } return holder; } catch (Throwable e) { LOG.warn("Can't convert IP to GeoIp", e); } return null; }