@VisibleForTesting Optional<GeoLocationInformation> extractGeoLocationInformation(Object fieldValue) { final InetAddress ipAddress; if (fieldValue instanceof InetAddress) { ipAddress = (InetAddress) fieldValue; } else if (fieldValue instanceof String) { ipAddress = getIpFromFieldValue((String) fieldValue); } else { ipAddress = null; } GeoLocationInformation geoLocationInformation = null; if (ipAddress != null) { try (Timer.Context ignored = resolveTime.time()) { final CityResponse response = databaseReader.city(ipAddress); final Location location = response.getLocation(); final Country country = response.getCountry(); final City city = response.getCity(); geoLocationInformation = GeoLocationInformation.create( location.getLatitude(), location.getLongitude(), country.getGeoNameId() != null ? country.getIsoCode() : "N/A", city.getGeoNameId() != null ? city.getName() : "N/A" // calling to .getName() may throw a NPE ); } catch (Exception e) { LOG.debug("Could not get location from IP {}", ipAddress.getHostAddress(), e); } } return Optional.ofNullable(geoLocationInformation); }
case MAXMIND_CITY: try { final CityResponse city = reader.city(addr); if (city == null) { LOG.debug("No city data for IP address {}, returning empty result.", addr);
CityResponse response = reader.city(InetAddress.getByName(ipAddress));
readLock.lock(); InetAddress addr = InetAddress.getByName(ip); CityResponse cityResponse = reader.city(addr); HashMap<String, String> geoInfo = new HashMap<>();
public CityResponse lookupCity(String ip) { if (this.reader != null) { CityResponse response; try { try { response = this.reader.city(InetAddress.getByName(ip)); return response; } catch (AddressNotFoundException e) { return null; } } catch (IOException | GeoIp2Exception e) { LoggerFactory.getLogger(getClass()).error("lookupCity", e); } } return null; }
private GeoInfo _getGeoInfo(String ipAddress) { GeoInfo geoInfo = new GeoInfo(); if (ipAddress == null) { return geoInfo; } try{ InetAddress inetAddress = InetAddress.getByName(ipAddress); CityResponse response = reader.city(inetAddress); Country country = response.getCountry(); Continent continent = response.getContinent(); City city = response.getCity(); Postal postal = response.getPostal(); Location location = response.getLocation(); Subdivision subdivision = response.getMostSpecificSubdivision(); geoInfo.setRegion(subdivision.getName()); geoInfo.setCountryIsoCode(country.getIsoCode()); geoInfo.setCountry(country.getName()); geoInfo.setContinent(continent.getCode()); geoInfo.setCity(city.getName()); geoInfo.setPostalCode(postal.getCode()); geoInfo.setLatitude(location.getLatitude()); geoInfo.setLongitude(location.getLongitude()); return geoInfo; } catch(Exception ex){ return null; } }
city = cityLookup.city(address); } catch (AddressNotFoundException e) { return;
public void dissect(final Parsable<?> parsable, final String inputname, final InetAddress ipAddress) throws DissectionFailure { // City is the 'Country' + more details. CityResponse response; try { response = reader.city(ipAddress); } catch (IOException | GeoIp2Exception e) { return; } extractCountryFields(parsable, inputname, response); extractCityFields(parsable, inputname, response); }
private Map<String, Object> extractGeoIp(InetAddress ipAddress) throws GeoIp2Exception, IOException { CityResponse response = databaseReader.city(ipAddress); if (LOCATION.getValue(response) == null) { return null; } Map<String, Object> geoIp = new HashMap<>(); for (Property property : properties) { Object propertyValue = property.getValue(response); if (propertyValue != null) { geoIp.put(property.toString(), propertyValue); } } return geoIp; }
InetAddress clientIp = InetAddress.getByName(ipString); final Location clientLocation = GEO_IP_DATABASE.city(clientIp).getLocation();
InetAddress clientIp = InetAddress.getByName(ipString); final Location clientLocation = GEO_IP_DATABASE.city(clientIp).getLocation();
@Override public GeoLocation readLocation(InetAddress address) { if(reader == null) { initializeDataset(); } GeoLocation geoLocation = null; try { if(reader != null) { Location location = reader.city(address).getLocation(); geoLocation = new GeoLocation(location.getLatitude(), location.getLongitude()); } } catch(IOException | GeoIp2Exception e) { if(logger != null) { logger.warn("Couldn't locate lat/long for address", e); } } return geoLocation; }
CityResponse l = ll.city(extAddress); if (l==null) { if (log.isDebugEnabled()) log.debug("Geo info failed to find location for address {}, using {}", extAddress, ll);
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; }
@Override public Location resolve(String ip) { try { CityResponse response = reader.city(InetAddress.getByName(ip)); Location location = new Location(); location.setCity(response.getCity().getName()); location.setCountryName(response.getCountry().getName()); location.setCountryCode(response.getCountry().getIsoCode()); location.setIp(ip); return location; } catch (IOException | GeoIp2Exception ex) { LOG.debug("Unable to resolve ip location", ex); } return null; }
try { InetAddress ipAddress = InetAddress.getByName(ip); CityResponse location = locationService.city(ipAddress); String countryCode = location.getCountry().getIsoCode(); double latitude = location.getLocation().getLatitude();
try { InetAddress ipAddress = InetAddress.getByName(ip); CityResponse location = locationService.city(ipAddress); String countryCode = location.getCountry().getIsoCode(); double latitude = location.getLocation().getLatitude();
CityResponse cityResponse = databaseReader.city(InetAddress.getByName(remoteAddr));
response = this.databaseReader.city(ipAddress); } catch (IOException | GeoIp2Exception e) { if (!this.required) {
response = this.databaseReader.city(ipAddress); } catch (IOException | GeoIp2Exception e) { if (!this.required) {