You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the official Java client library for the Ipregistry IP geolocation and threat data API,
allowing you to lookup your own IP address or specified ones. Responses return multiple data points including
carrier, company, currency, location, timezone, threat information, and more.
Getting Started
You'll need an Ipregistry API key, which you can get along with 100,000 free lookups by signing up for a free account at https://ipregistry.co.
try { // Here is an example to lookup IP address data for a given IP address. // The parameter to pass is an IPv4 or IPv6 address. // On server-side, you need to retrieve the client IP from the request headers. finalIpInfoipInfo = client.lookup("54.85.132.205"); System.out.println(ipInfo);
// If your purpose is to perform a lookup for the current node and network interface // used to execute this code, then you don't even need to pass a parameter finalRequesterIpInforequesterIpInfo = client.lookup(); System.out.println(requesterIpInfo); } catch (finalApiExceptione) { // Handle API errors (e.g. insufficient credits, throttling) here e.printStackTrace(); } catch (finalClientExceptione) { // Handle client errors (e.g. network error) here e.printStackTrace(); } }
for (inti = 0; i < ipInfoList.size(); i++) { try { finalIpInfoipInfo = ipInfoList.get(i); // Here is an example to print out the country name associated with each IP address System.out.println(ipInfo.getLocation().getCountry().getName()); } catch (finalIpInfoExceptione) { // Handle batch lookup error (e.g. invalid IP address) here e.printStackTrace(); } } } catch (finalApiExceptione) { // Handle API errors (e.g. insufficient credits, throttling) here e.printStackTrace(); } catch (finalClientExceptione) { // Handle client errors (e.g. network error) here e.printStackTrace(); } }
}
Caching
Although the Ipregistry client library has built-in support for in-memory caching, it is disabled by default to ensure data freshness.
To enable in-memory caching, pass an instance of InMemoryCache to the Ipregistry client:
// For testing purposes, you can retrieve you current user-agent value from: // https://api.ipregistry.co/user_agent?key=YOUR_API_KEY (look at the field named "user_agent") if (UserAgent.isBot("TO_REPLACE_BY_USER_AGENT_RETRIEVED_FROM_REQUEST_HEADER")) { try { finalIpDataipInfo = client.lookup("8.8.8.8"); // Here is an example to print out the country name associated with the IP address System.out.println(ipInfo.getLocation().getCountry().getName()); } catch (finalApiExceptione) { // Handle API errors (e.g. insufficient credits, throttling) here e.printStackTrace(); } catch (finalClientExceptione) { // Handle client errors (e.g. network error) here e.printStackTrace(); } } }
}
Other Libraries
There are official Ipregistry client libraries available for many languages including
Javascript,
Python,
Typescript and more.
Are you looking for an official client with a programming language or framework we do not support yet?
let us know.
About
Official Java Client for Ipregistry, a Fast, Reliable IP Geolocation and Threat Data API.