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.
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.
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>importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out the hostnameSystem.out.println(response.getHostname());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
ASNResponseresponse = ipInfo.lookupASN("AS7922");
// Print out country nameSystem.out.println(response.getCountry());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}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.
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.
importio.ipinfo.api.IPinfoLite;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponseLite;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoLiteipInfoLite = newIPinfoLite.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseLiteresponse = ipInfoLite.lookupIP("8.8.8.8");
// Print out the ASNSystem.out.println(response.getAsn()); // AS15169// Print out the country codeSystem.out.println(response.getCountryCode()); // US// Print out the country nameSystem.out.println(response.getCountry()); // United States
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}The library also supports the Core API, which provides city-level geolocation with nested geo and AS objects. Authentication with your token is required.
importio.ipinfo.api.IPinfoCore;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponseCore;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoCoreipInfoCore = newIPinfoCore.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseCoreresponse = ipInfoCore.lookupIP("8.8.8.8");
// Print out the IPSystem.out.println(response.getIp()); // 8.8.8.8// Print out geo informationSystem.out.println(response.getGeo().getCity()); // Mountain ViewSystem.out.println(response.getGeo().getCountry()); // United States// Print out AS informationSystem.out.println(response.getAs().getAsn()); // AS15169System.out.println(response.getAs().getName()); // Google LLC
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}The library also supports the Plus API, which provides enhanced data including mobile carrier info and privacy detection. Authentication with your token is required.
importio.ipinfo.api.IPinfoPlus;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponsePlus;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoPlusipInfoPlus = newIPinfoPlus.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponsePlusresponse = ipInfoPlus.lookupIP("8.8.8.8");
// Print out the IPSystem.out.println(response.getIp()); // 8.8.8.8// Print out geo informationSystem.out.println(response.getGeo().getCity()); // Mountain View// Print out mobile and anonymous infoSystem.out.println(response.getMobile());
System.out.println(response.getAnonymous().isProxy()); // false
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}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.
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.ResproxyResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
ResproxyResponseresponse = ipInfo.lookupResproxy("175.107.211.204");
// Print out the IPSystem.out.println(response.getIp()); // 175.107.211.204// Print out resproxy detailsSystem.out.println(response.getLastSeen()); // 2025-01-20System.out.println(response.getPercentDaysSeen()); // 0.85System.out.println(response.getService()); // Bright Data
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}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.
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
// 5 Day CacheIPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.setCache(newSimpleCache(Duration.ofDays(5)))
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out the hostnameSystem.out.println(response.getHostname());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}This library provides a system to lookup country names through ISO2 country codes.
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out the country codeSystem.out.println(response.getCountryCode());
// Print out the country nameSystem.out.println(response.getCountryName());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}This library provides a system to lookup if a country is a member of the European Union (EU) through ISO2 country codes.
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out whether the country is a member of the EUSystem.out.println(response.isEU());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}This library provides a system to lookup if a country is a member of the European Union (EU), emoji and unicode of the country's flag, code and symbol of the country's currency, and public link to the country's flag image as an SVG and continent code and name through ISO2 country codes.
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out whether the country is a member of the EUSystem.out.println(response.isEU());
// CountryFlag{emoji='🇺🇸',unicode='U+1F1FA U+1F1F8'}System.out.println(response.getCountryFlag());
// https://cdn.ipinfo.io/static/images/countries-flags/US.svgSystem.out.println(response.getCountryFlagURL());
// CountryCurrency{code='USD',symbol='$'}System.out.println(response.getCountryCurrency());
// Continent{code='NA',name='North America'}System.out.println(response.getContinent());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}This library provides an easy way to get the latitude and longitude of an IP Address:
importio.ipinfo.api.IPinfo;
importio.ipinfo.api.errors.RateLimitedException;
importio.ipinfo.api.model.IPResponse;
publicclassMain {
publicstaticvoidmain(String... args) {
IPinfoipInfo = newIPinfo.Builder()
.setToken("YOUR TOKEN")
.build();
try {
IPResponseresponse = ipInfo.lookupIP("8.8.8.8");
// Print out the Latitude and LongitudeSystem.out.println(response.getLatitude());
System.out.println(response.getLongitude());
} catch (RateLimitedExceptionex) {
// Handle rate limits here.
}
}
}- This library is thread-safe. Feel free to call the different endpoints from different threads.
- This library uses Square's http client. Please refer to their documentation to get information on more functionality you can use.
There are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.