use of com.maxmind.geoip2.model.CityResponse in project nutch by apache.
the class GeoIPDocumentCreator method createDocFromCityDb.
public static NutchDocument createDocFromCityDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
addIfNotNull(doc, "ip", serverIp);
CityResponse response = reader.city(InetAddress.getByName(serverIp));
City city = response.getCity();
// 'Minneapolis'
addIfNotNull(doc, "cityName", city.getName());
// 50
addIfNotNull(doc, "cityConfidence", city.getConfidence());
addIfNotNull(doc, "cityGeoNameId", city.getGeoNameId());
Continent continent = response.getContinent();
addIfNotNull(doc, "continentCode", continent.getCode());
addIfNotNull(doc, "continentGeoNameId", continent.getGeoNameId());
addIfNotNull(doc, "continentName", continent.getName());
Country country = response.getCountry();
// 'US'
addIfNotNull(doc, "countryIsoCode", country.getIsoCode());
// 'United States'
addIfNotNull(doc, "countryName", country.getName());
// 99
addIfNotNull(doc, "countryConfidence", country.getConfidence());
addIfNotNull(doc, "countryGeoName", country.getGeoNameId());
Location location = response.getLocation();
// 44.9733,
addIfNotNull(doc, "latLon", location.getLatitude() + "," + location.getLongitude());
// -93.2323
// 3
addIfNotNull(doc, "accRadius", location.getAccuracyRadius());
// 'America/Chicago'
addIfNotNull(doc, "timeZone", location.getTimeZone());
addIfNotNull(doc, "metroCode", location.getMetroCode());
Postal postal = response.getPostal();
// '55455'
addIfNotNull(doc, "postalCode", postal.getCode());
// 40
addIfNotNull(doc, "postalConfidence", postal.getConfidence());
RepresentedCountry rCountry = response.getRepresentedCountry();
addIfNotNull(doc, "countryType", rCountry.getType());
Subdivision subdivision = response.getMostSpecificSubdivision();
// 'Minnesota'
addIfNotNull(doc, "subDivName", subdivision.getName());
// 'MN'
addIfNotNull(doc, "subDivIdoCode", subdivision.getIsoCode());
// 90
addIfNotNull(doc, "subDivConfidence", subdivision.getConfidence());
addIfNotNull(doc, "subDivGeoNameId", subdivision.getGeoNameId());
return doc;
}
use of com.maxmind.geoip2.model.CityResponse in project nutch by apache.
the class GeoIPDocumentCreator method createDocFromInsightsService.
public static NutchDocument createDocFromInsightsService(String serverIp, NutchDocument doc, WebServiceClient client) throws UnknownHostException, IOException, GeoIp2Exception {
addIfNotNull(doc, "ip", serverIp);
InsightsResponse response = client.insights(InetAddress.getByName(serverIp));
// CityResponse response = client.city(InetAddress.getByName(serverIp));
City city = response.getCity();
// 'Minneapolis'
addIfNotNull(doc, "cityName", city.getName());
// 50
addIfNotNull(doc, "cityConfidence", city.getConfidence());
addIfNotNull(doc, "cityGeoNameId", city.getGeoNameId());
Continent continent = response.getContinent();
addIfNotNull(doc, "continentCode", continent.getCode());
addIfNotNull(doc, "continentGeoNameId", continent.getGeoNameId());
addIfNotNull(doc, "continentName", continent.getName());
Country country = response.getCountry();
// 'US'
addIfNotNull(doc, "countryIsoCode", country.getIsoCode());
// 'United States'
addIfNotNull(doc, "countryName", country.getName());
// 99
addIfNotNull(doc, "countryConfidence", country.getConfidence());
addIfNotNull(doc, "countryGeoName", country.getGeoNameId());
Location location = response.getLocation();
// 44.9733,
addIfNotNull(doc, "latLon", location.getLatitude() + "," + location.getLongitude());
// -93.2323
// 3
addIfNotNull(doc, "accRadius", location.getAccuracyRadius());
// 'America/Chicago'
addIfNotNull(doc, "timeZone", location.getTimeZone());
addIfNotNull(doc, "metroCode", location.getMetroCode());
Postal postal = response.getPostal();
// '55455'
addIfNotNull(doc, "postalCode", postal.getCode());
// 40
addIfNotNull(doc, "postalConfidence", postal.getConfidence());
RepresentedCountry rCountry = response.getRepresentedCountry();
addIfNotNull(doc, "countryType", rCountry.getType());
Subdivision subdivision = response.getMostSpecificSubdivision();
// 'Minnesota'
addIfNotNull(doc, "subDivName", subdivision.getName());
// 'MN'
addIfNotNull(doc, "subDivIdoCode", subdivision.getIsoCode());
// 90
addIfNotNull(doc, "subDivConfidence", subdivision.getConfidence());
addIfNotNull(doc, "subDivGeoNameId", subdivision.getGeoNameId());
Traits traits = response.getTraits();
addIfNotNull(doc, "autonSystemNum", traits.getAutonomousSystemNumber());
addIfNotNull(doc, "autonSystemOrg", traits.getAutonomousSystemOrganization());
addIfNotNull(doc, "domain", traits.getDomain());
addIfNotNull(doc, "isp", traits.getIsp());
addIfNotNull(doc, "org", traits.getOrganization());
addIfNotNull(doc, "userType", traits.getUserType());
// for better results, users should upgrade to
// https://www.maxmind.com/en/solutions/geoip2-enterprise-product-suite/anonymous-ip-database
addIfNotNull(doc, "isAnonProxy", String.valueOf(traits.isAnonymousProxy()));
return doc;
}
use of com.maxmind.geoip2.model.CityResponse in project tutorials by eugenp.
the class RawDBDemoGeoIPLocationService method getLocation.
public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception {
InetAddress ipAddress = InetAddress.getByName(ip);
CityResponse response = dbReader.city(ipAddress);
String cityName = response.getCity().getName();
String latitude = response.getLocation().getLatitude().toString();
String longitude = response.getLocation().getLongitude().toString();
return new GeoIP(ip, cityName, latitude, longitude);
}
use of com.maxmind.geoip2.model.CityResponse in project Essentials by EssentialsX.
the class EssentialsGeoIPPlayerListener method delayedJoin.
public void delayedJoin(Player player) {
User u = ess.getUser(player);
if (u.isAuthorized("essentials.geoip.hide") || player.getAddress() == null) {
return;
}
InetAddress address = player.getAddress().getAddress();
StringBuilder sb = new StringBuilder();
try {
if (config.getBoolean("database.show-cities", false)) {
CityResponse response = mmreader.city(address);
if (response == null) {
return;
}
String city;
String region;
String country;
city = response.getCity().getName();
region = response.getMostSpecificSubdivision().getName();
country = response.getCountry().getName();
if (city != null) {
sb.append(city).append(", ");
}
if (region != null) {
sb.append(region).append(", ");
}
sb.append(country);
} else {
CountryResponse response = mmreader.country(address);
sb.append(response.getCountry().getName());
}
} catch (AddressNotFoundException ex) {
// GeoIP2 API forced this when address not found in their DB. jar will not complied without this.
// TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties.
logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage());
} catch (IOException | GeoIp2Exception ex) {
// GeoIP2 API forced this when address not found in their DB. jar will not complied without this.
logger.log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage());
}
if (config.getBoolean("show-on-whois", true)) {
u.setGeoLocation(sb.toString());
}
if (config.getBoolean("show-on-login", true) && !u.isHidden()) {
for (Player onlinePlayer : player.getServer().getOnlinePlayers()) {
User user = ess.getUser(onlinePlayer);
if (user.isAuthorized("essentials.geoip.show")) {
user.sendMessage(tl("geoipJoinFormat", u.getDisplayName(), sb.toString()));
}
}
}
}
use of com.maxmind.geoip2.model.CityResponse in project arctic-sea by 52North.
the class StatisticsLocationUtil method ip2SpatialData.
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;
}
Aggregations