Search in sources :

Example 16 with Country

use of com.maxmind.geoip2.record.Country in project nutch by apache.

the class GeoIPDocumentCreator method createDocFromInsightsService.

public static NutchDocument createDocFromInsightsService(String serverIp, NutchDocument doc, WebServiceClient client) throws UnknownHostException, IOException, GeoIp2Exception {
    doc.add("ip", serverIp);
    InsightsResponse response = client.insights(InetAddress.getByName(serverIp));
    // CityResponse response = client.city(InetAddress.getByName(serverIp));
    City city = response.getCity();
    // 'Minneapolis'
    doc.add("cityName", city.getName());
    // 50
    doc.add("cityConfidence", city.getConfidence());
    doc.add("cityGeoNameId", city.getGeoNameId());
    Continent continent = response.getContinent();
    doc.add("continentCode", continent.getCode());
    doc.add("continentGeoNameId", continent.getGeoNameId());
    doc.add("continentName", continent.getName());
    Country country = response.getCountry();
    // 'US'
    doc.add("countryIsoCode", country.getIsoCode());
    // 'United States'
    doc.add("countryName", country.getName());
    // 99
    doc.add("countryConfidence", country.getConfidence());
    doc.add("countryGeoName", country.getGeoNameId());
    Location location = response.getLocation();
    // 44.9733,
    doc.add("latLon", location.getLatitude() + "," + location.getLongitude());
    // -93.2323
    // 3
    doc.add("accRadius", location.getAccuracyRadius());
    // 'America/Chicago'
    doc.add("timeZone", location.getTimeZone());
    doc.add("metroCode", location.getMetroCode());
    Postal postal = response.getPostal();
    // '55455'
    doc.add("postalCode", postal.getCode());
    // 40
    doc.add("postalConfidence", postal.getConfidence());
    RepresentedCountry rCountry = response.getRepresentedCountry();
    doc.add("countryType", rCountry.getType());
    Subdivision subdivision = response.getMostSpecificSubdivision();
    // 'Minnesota'
    doc.add("subDivName", subdivision.getName());
    // 'MN'
    doc.add("subDivIdoCode", subdivision.getIsoCode());
    // 90
    doc.add("subDivConfidence", subdivision.getConfidence());
    doc.add("subDivGeoNameId", subdivision.getGeoNameId());
    Traits traits = response.getTraits();
    doc.add("autonSystemNum", traits.getAutonomousSystemNumber());
    doc.add("autonSystemOrg", traits.getAutonomousSystemOrganization());
    doc.add("domain", traits.getDomain());
    doc.add("isp", traits.getIsp());
    doc.add("org", traits.getOrganization());
    doc.add("userType", traits.getUserType());
    doc.add("isAnonProxy", traits.isAnonymousProxy());
    doc.add("isSatelliteProv", traits.isSatelliteProvider());
    return doc;
}
Also used : Continent(com.maxmind.geoip2.record.Continent) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) Country(com.maxmind.geoip2.record.Country) InsightsResponse(com.maxmind.geoip2.model.InsightsResponse) City(com.maxmind.geoip2.record.City) Subdivision(com.maxmind.geoip2.record.Subdivision) Postal(com.maxmind.geoip2.record.Postal) Traits(com.maxmind.geoip2.record.Traits) Location(com.maxmind.geoip2.record.Location)

Example 17 with Country

use of com.maxmind.geoip2.record.Country in project nutch by apache.

the class GeoIPDocumentCreator method createDocFromCityDb.

public static NutchDocument createDocFromCityDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
    doc.add("ip", serverIp);
    CityResponse response = reader.city(InetAddress.getByName(serverIp));
    City city = response.getCity();
    // 'Minneapolis'
    doc.add("cityName", city.getName());
    // 50
    doc.add("cityConfidence", city.getConfidence());
    doc.add("cityGeoNameId", city.getGeoNameId());
    Continent continent = response.getContinent();
    doc.add("continentCode", continent.getCode());
    doc.add("continentGeoNameId", continent.getGeoNameId());
    doc.add("continentName", continent.getName());
    Country country = response.getCountry();
    // 'US'
    doc.add("countryIsoCode", country.getIsoCode());
    // 'United States'
    doc.add("countryName", country.getName());
    // 99
    doc.add("countryConfidence", country.getConfidence());
    doc.add("countryGeoName", country.getGeoNameId());
    Location location = response.getLocation();
    // 44.9733,
    doc.add("latLon", location.getLatitude() + "," + location.getLongitude());
    // -93.2323
    // 3
    doc.add("accRadius", location.getAccuracyRadius());
    // 'America/Chicago'
    doc.add("timeZone", location.getTimeZone());
    doc.add("metroCode", location.getMetroCode());
    Postal postal = response.getPostal();
    // '55455'
    doc.add("postalCode", postal.getCode());
    // 40
    doc.add("postalConfidence", postal.getConfidence());
    RepresentedCountry rCountry = response.getRepresentedCountry();
    doc.add("countryType", rCountry.getType());
    Subdivision subdivision = response.getMostSpecificSubdivision();
    // 'Minnesota'
    doc.add("subDivName", subdivision.getName());
    // 'MN'
    doc.add("subDivIdoCode", subdivision.getIsoCode());
    // 90
    doc.add("subDivConfidence", subdivision.getConfidence());
    doc.add("subDivGeoNameId", subdivision.getGeoNameId());
    return doc;
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) Continent(com.maxmind.geoip2.record.Continent) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) Country(com.maxmind.geoip2.record.Country) City(com.maxmind.geoip2.record.City) Subdivision(com.maxmind.geoip2.record.Subdivision) Postal(com.maxmind.geoip2.record.Postal) Location(com.maxmind.geoip2.record.Location)

Example 18 with Country

use of com.maxmind.geoip2.record.Country 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()));
            }
        }
    }
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) CountryResponse(com.maxmind.geoip2.model.CountryResponse) InetAddress(java.net.InetAddress)

Example 19 with Country

use of com.maxmind.geoip2.record.Country 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;
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) GeoPoint(org.elasticsearch.common.geo.GeoPoint) HashMap(java.util.HashMap) Country(com.maxmind.geoip2.record.Country) IAdminStatisticsLocation(org.n52.iceland.statistics.api.interfaces.geolocation.IAdminStatisticsLocation) Location(com.maxmind.geoip2.record.Location)

Example 20 with Country

use of com.maxmind.geoip2.record.Country in project Essentials by drtshock.

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()));
            }
        }
    }
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) CountryResponse(com.maxmind.geoip2.model.CountryResponse) InetAddress(java.net.InetAddress)

Aggregations

CityResponse (com.maxmind.geoip2.model.CityResponse)12 Country (com.maxmind.geoip2.record.Country)11 AddressNotFoundException (com.maxmind.geoip2.exception.AddressNotFoundException)10 Location (com.maxmind.geoip2.record.Location)9 IOException (java.io.IOException)9 InetAddress (java.net.InetAddress)8 CountryResponse (com.maxmind.geoip2.model.CountryResponse)7 City (com.maxmind.geoip2.record.City)7 Continent (com.maxmind.geoip2.record.Continent)7 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)6 GeoIp2Exception (com.maxmind.geoip2.exception.GeoIp2Exception)5 Postal (com.maxmind.geoip2.record.Postal)5 RepresentedCountry (com.maxmind.geoip2.record.RepresentedCountry)4 Subdivision (com.maxmind.geoip2.record.Subdivision)4 GeoDef (com.quickutil.platform.def.GeoDef)4 JsonObject (com.google.gson.JsonObject)3 Traits (com.maxmind.geoip2.record.Traits)3 User (com.earth2me.essentials.User)2 MaxMind (com.maxmind.geoip2.record.MaxMind)2