Java
Official Java library for IPinfo API (IP geolocation and other types of IP data)
Install / Use
/learn @ipinfo/JavaREADME
<img src="https://ipinfo.io/static/ipinfo-small.svg" alt="IPinfo" width="24"/> IPinfo Java Client Library
This is the official Java client library for the IPinfo.io IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:
- IP geolocation data (city, region, country, postal code, latitude, and longitude)
- ASN information (ISP or network operator, associated domain name, and type, such as business, hosting, or company)
- Company data (the name and domain of the business that uses the IP address)
- Carrier details (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
Check all the data we have for your IP address here.
Getting Started
You'll need an IPinfo API access token, which you can get by signing up for a free account at https://ipinfo.io/signup.
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see https://ipinfo.io/pricing
Click here to view the Java SDK's API documentation.
The library also supports the Lite API, see the Lite API section for more info.
Installation
Maven
Add these values to your pom.xml file:
Dependency:
<dependencies>
<dependency>
<groupId>io.ipinfo</groupId>
<artifactId>ipinfo-api</artifactId>
<version>3.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Quick Start
IP Information
import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponse;
public class Main {
public static void main(String... args) {
IPinfo ipInfo = new IPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponse response = ipInfo.lookupIP("8.8.8.8");
// Print out the hostname
System.out.println(response.getHostname());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
ASN Information
import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponse;
public class Main {
public static void main(String... args) {
IPinfo ipInfo = new IPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
ASNResponse response = ipInfo.lookupASN("AS7922");
// Print out country name
System.out.println(response.getCountry());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Errors
ErrorResponseException: A runtime exception accessible through theExecutionExceptionof a future. This exception signals that something went wrong when mapping the API response to the wrapper. You probably can't recover from this exception.RateLimitedExceptionAn exception signaling that you've been rate limited.
Lite API
The library gives the possibility to use the Lite API too, authentication with your token is still required.
The returned details are slightly different from the Core API.
import io.ipinfo.api.IPinfoLite;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponseLite;
public class Main {
public static void main(String... args) {
IPinfoLite ipInfoLite = new IPinfoLite.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseLite response = ipInfoLite.lookupIP("8.8.8.8");
// Print out the ASN
System.out.println(response.getAsn()); // AS15169
// Print out the country code
System.out.println(response.getCountryCode()); // US
// Print out the country name
System.out.println(response.getCountry()); // United States
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Core API
The library also supports the Core API, which provides city-level geolocation with nested geo and AS objects. Authentication with your token is required.
import io.ipinfo.api.IPinfoCore;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponseCore;
public class Main {
public static void main(String... args) {
IPinfoCore ipInfoCore = new IPinfoCore.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseCore response = ipInfoCore.lookupIP("8.8.8.8");
// Print out the IP
System.out.println(response.getIp()); // 8.8.8.8
// Print out geo information
System.out.println(response.getGeo().getCity()); // Mountain View
System.out.println(response.getGeo().getCountry()); // United States
// Print out AS information
System.out.println(response.getAs().getAsn()); // AS15169
System.out.println(response.getAs().getName()); // Google LLC
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Plus API
The library also supports the Plus API, which provides enhanced data including mobile carrier info and privacy detection. Authentication with your token is required.
import io.ipinfo.api.IPinfoPlus;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponsePlus;
public class Main {
public static void main(String... args) {
IPinfoPlus ipInfoPlus = new IPinfoPlus.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponsePlus response = ipInfoPlus.lookupIP("8.8.8.8");
// Print out the IP
System.out.println(response.getIp()); // 8.8.8.8
// Print out geo information
System.out.println(response.getGeo().getCity()); // Mountain View
// Print out mobile and anonymous info
System.out.println(response.getMobile());
System.out.println(response.getAnonymous().isProxy()); // false
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Residential Proxy API
The library also supports the Residential Proxy API, which allows you to check if an IP address is a residential proxy. Authentication with your token is required.
import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.ResproxyResponse;
public class Main {
public static void main(String... args) {
IPinfo ipInfo = new IPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
ResproxyResponse response = ipInfo.lookupResproxy("175.107.211.204");
// Print out the IP
System.out.println(response.getIp()); // 175.107.211.204
// Print out resproxy details
System.out.println(response.getLastSeen()); // 2025-01-20
System.out.println(response.getPercentDaysSeen()); // 0.85
System.out.println(response.getService()); // Bright Data
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Caching
This library provides a very simple caching system accessible in SimpleCache.
Simple cache is an in-memory caching system that resets every time you restart
your code.
If you prefer a different caching methodology, you may use the Cache
interface and implement your own caching system around your own infrastructure.
The default cache length is 1 day, this can be changed by calling the SimpleCache constructor yourself.
import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponse;
public class Main {
public static void main(String... args) {
// 5 Day Cache
IPinfo ipInfo = new IPinfo.Builder()
.setToken("YOUR TOKEN")
.setCache(new SimpleCache(Duration.ofDays(5)))
.build();
try {
IPResponse response = ipInfo.lookupIP("8.8.8.8");
// Print out the hostname
System.out.println(response.getHostname());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
Country Name Lookup
This library provides a system to lookup country names through ISO2 country codes.
import io.ipinfo.api.IPinfo;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponse;
public class Main {
public static void main(String... args) {
IPinfo ipInfo = new IPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponse response = ipInfo.lookupIP("8.8.8.8");
// Print out the country code
System.out.println(response.getCountryCode());
// Print out the country name
System.out.println(response.getCountryName());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
EU Cou
Related Skills
gh-issues
346.4kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
oracle
346.4kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
taskflow-inbox-triage
346.4kname: taskflow-inbox-triage description: Example TaskFlow authoring pattern for inbox triage. Use when messages need different treatment based on intent, with some routes notifying immediately, some w
