-
Notifications
You must be signed in to change notification settings - Fork 4
Loading and Querying Ipregistry Datasets
Laurent Pellegrino edited this page May 8, 2023
·
2 revisions
The ipregistry-java library package includes a class to load and query Ipregistry datatasets.
Hereafter are examples for the Ipregistry geolocation dataset.
package co.ipregistry.datasets;
import co.ipregistry.datasets.model.GeolocationData;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Paths;
public class IpregistryGeolocationDatasetTest {
@Test
public void test() throws IOException {
try (IpregistryGeolocationDataset dataset =
IpregistryGeolocationDataset.builder("YOUR_SECRET_KEY").build()) {
System.out.println(dataset.getBuildDate());
GeolocationData data = dataset.lookup("8.8.8.8");
System.out.println(data);
}
}
}
Assuming you have downloaded an Ipregistry Geolocation MMDB file locally, then you can load it as follows:
try (IpregistryGeolocationDataset dataset =
IpregistryGeolocationDataset.builder(Paths.get("/path/to/ipregistry-geolocation.mmdb")).build()) {
System.out.println(dataset.getBuildDate());
GeolocationData data = dataset.lookup("8.8.8.8");
System.out.println(data);
}
dataset.update("YOUR_SECRET_KEY", LoadingMode.MEMORY).get();
dataset.update(Paths.get("/path/to/ipregistry-geolocation.mmdb"), LoadingMode.MEMORY);