- Notifications
You must be signed in to change notification settings - Fork0
Official Java client library for IPinfo
License
MoneyDOC/java
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is the official Java client library for theIPinfo.io IP address API, allowing you to lookup your own IP address, or get any of the following details for an IP:
- IP geolocation (city, region, country, postal code, latitude and longitude)
- ASN details (ISP or network operator, associated domain name, and type, such as business, hosting or company)
- Company details (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)
You'll need an IPinfo API access token, which you can get by singing up for a free account athttps://ipinfo.io/signup.
The free plan is limited to 1,000 requests a day, 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 seehttps://ipinfo.io/pricing
Add these values to your pom.xml file:
Dependency:
<dependencies> <dependency> <groupId>io.ipinfo</groupId> <artifactId>ipinfo-api</artifactId> <version>1.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 =IPInfo.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 =IPInfo.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 the ExecutionException of 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.
RateLimitedException An exception signalling that you've been rate limited.
This library provides a very simple caching system accessible inSimpleCache. 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 theCache 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 =IPInfo.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.
By default, this translation exists for English (United States). If you wish to provide a different language mapping, just use the following system in the builder:
importio.ipinfo.api.IPInfo;importio.ipinfo.api.errors.RateLimitedException;importio.ipinfo.api.model.IPResponse;publicclassMain {publicstaticvoidmain(String...args) {IPInfoipInfo =IPInfo.builder().setToken("YOUR TOKEN").setCountryFile(newFile("path/to/file.json")).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 file must follow the same layout as seenhere
More language files can be foundhere
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 =IPInfo.builder().setToken("YOUR TOKEN").setCountryFile(newFile("path/to/file.json")).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.
https://ipinfo.io/developers/libraries
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 and IP type data sets. Our API handles over 12 billion requests a month for 100,000 businesses and developers.
About
Official Java client library for IPinfo
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Java93.9%
- Shell6.1%