在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipinfo/java开源软件地址:https://github.com/ipinfo/java开源编程语言:Java 97.7%开源软件介绍:IPinfo Java Client LibraryThis is the official Java client library for the IPinfo.io IP address API, allowing you to lookup your own IP address, or get any of the following details for an IP:
Check all the data we have for your IP address here. Getting StartedYou'll need an IPinfo API access token, which you can get by singing 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. InstallationMavenAdd these values to your pom.xml file: Dependency: <dependencies>
<dependency>
<groupId>io.ipinfo</groupId>
<artifactId>ipinfo-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
</dependencies> Quick StartIP Informationimport 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 Informationimport 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
CachingThis library provides a very simple caching system accessible in If you prefer a different caching methodology, you may use the 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 LookupThis 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: 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")
.setCountryFile(new File("path/to/file.json"))
.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.
}
}
} This file must follow the same layout as seen here More language files can be found here Location InformationThis library provides an easy way to get the latitude and longitude of an IP Address: 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")
.setCountryFile(new File("path/to/file.json"))
.build();
try {
IPResponse response = ipInfo.lookupIP("8.8.8.8");
// Print out the Latitude and Longitude
System.out.println(response.getLatitude());
System.out.println(response.getLongitude());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
} Extra Information
Other LibrariesThere 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. About IPinfoFounded 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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论