|
Name |
GeoIpService |
|
Class Path |
|
|
Versions |
9 10 11 |
Overview
The GeoIpService provides functionality for resolving IP addresses to geographic locations using a GeoIP database. It allows for loading a database file and performing lookups to retrieve city-level location information.
Available Functions
setDatabaseFileLocation(String databaseFileLocation)
Sets the location of the GeoIP database file and initializes the database reader.
-
Parameters:
-
databaseFileLocation(String): The file path of the GeoIP database.
-
-
Exceptions:
-
Throws
RuntimeExceptionif the file cannot be read.
-
resolveIpToLocation(String ip): String
Resolves an IP address to a geographic location.
-
Parameters:
-
ip(String): The IP address to look up.
-
-
Returns:
-
String: A JSON string representing the resolved location details. -
{"error" : "invalid IP"}if the provided IP address is invalid. -
{"error" : "Not found"}if no location data is found for the IP. -
Throws
RuntimeExceptionif there is an issue reading the database.
-
Internal Components
(For internal processing, not intended for direct use.)
-
GeoDatabaseReaderFactory
A factory interface for creatingDatabaseReaderinstances. -
DatabaseReader databaseReader
The MaxMindDatabaseReaderinstance used to look up IP addresses.
Summary
The GeoIpService allows applications to:
-
Load a GeoIP database file.
-
Perform city-level lookups for given IP addresses.
-
Handle invalid or missing IP data gracefully.
This service is essential for integrating geographic IP resolution into security or analytics workflows.