Class GeoIpService

java.lang.Object
host.anzo.core.service.GeoIpService

public class GeoIpService extends Object
Provides GeoIP lookup services using MaxMind databases and web services.

This service initializes on startup and offers methods to retrieve geographical information based on IP addresses. It supports both local database lookups (GeoLite2-City) and web service-based insights (requires valid MaxMind credentials).

Configuration:

  • Requires GeoLite2-City.mmdb in classpath
  • Web service requires system properties maxMindAccountId and maxMindLicenseKey
Since:
10/24/2018
  • Method Details

    • getCity

      public com.maxmind.geoip2.model.CityResponse getCity(String ipAddress)
      Retrieves city-level information for a given IP address using the local database.
      Parameters:
      ipAddress - IP address to query (e.g., "192.168.1.1")
      Returns:
      CityResponse with geographical data, or null if:
      • Database not initialized
      • Invalid IP format
      • Lookup error occurs
    • getCountryName

      public String getCountryName(String ipAddress)
      Retrieves the country name associated with an IP address using the local database.
      Parameters:
      ipAddress - IP address to query
      Returns:
      Country name as String, or null if:
      • Database not initialized
      • Country data unavailable
      • Lookup error occurs
    • getInsights

      public com.maxmind.geoip2.model.InsightsResponse getInsights(String ipAddress)
      Retrieves detailed insights for an IP address using MaxMind's web service.

      Requires valid maxMindAccountId and maxMindLicenseKey system properties.

      Parameters:
      ipAddress - IP address to query
      Returns:
      InsightsResponse with extended data, or null if:
      • Web service client not initialized
      • Invalid credentials
      • Lookup error occurs
    • getInfo

      public StatsSet getInfo(String ipAddress, boolean full)
      Builds a StatsSet with geo-location data for an IP address.

      Includes different data tiers based on the full parameter:

      • Basic (full=false): City, country, coordinates, network traits
      • Full (full=true): ISP, organization, proxy detection, mobile codes
      Parameters:
      ipAddress - IP address to analyze
      full - true to include extended insights data
      Returns:
      Populated StatsSet, or null on any error
      See Also: