Skip to content

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.

Loading and querying a dataset using your Ipregistry datasets secret key

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);
        }
    }

}

Loading and querying a dataset from a local Ipregistry MMDB file

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);
}

Triggering an update that downloads the latest version of the dataset using your secret key

dataset.update("YOUR_SECRET_KEY", LoadingMode.MEMORY).get();

Triggering an update using an MMDB file you have on the disk

dataset.update(Paths.get("/path/to/ipregistry-geolocation.mmdb"), LoadingMode.MEMORY);