# [<img src="https://ipinfo.io/static/ipinfo-small.svg" alt="IPinfo" width="24"/>](https://ipinfo.io/) IPinfo Java Client Library
[![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE)
This is the official Java client library for the [IPinfo.io](https://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](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)
- [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)
- [Company data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
- [Carrier details](https://ipinfo.io/ip-carrier-api) (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](https://ipinfo.io/what-is-my-ip).
### 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](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](https://ipinfo.io/pricing)
[Click here to view the Java SDK's API documentation](https://ipinfo.github.io/java/).
#### Installation
##### Maven
Add these values to your pom.xml file:
Dependency:
```xml
<dependencies>
<dependency>
<groupId>io.ipinfo</groupId>
<artifactId>ipinfo-api</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
```
#### Quick Start
##### IP Information
````java
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
````java
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 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 signaling that you've been rate limited.
#### 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.
```java
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.
```java
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 Country Lookup
This library provides a system to lookup if a country is a member of the European Union (EU) through
ISO2 country codes.
```java
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 whether the country is a member of the EU
System.out.println(response.isEU());
} catch (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
```
#### Internationalization
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.
```java
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 whether the country is a member of the EU
System.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.svg
System.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 (RateLimitedException ex) {
// Handle rate limits here.
}
}
}
```
#### Location Information
This library provides an easy way to get the latitude and longitude of an IP Address:
```java
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.lo
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
IPinfo Java 客户端库这是IPinfo.io IP 地址 API的官方 Java 客户端库,允许您查找自己的 IP 地址,或获取以下任何 IP 详细信息IP 地理位置数据(城市、地区、国家、邮政编码、纬度和经度)ASN 信息(ISP 或网络运营商、关联域名和类型,例如企业、托管或公司)公司数据(使用 IP 地址的企业名称和域名)运营商详细信息(如果 IP 专门用于移动流量,则为移动运营商的名称以及该运营商的 MNC 和 MCC)在此检查我们拥有的您的 IP 地址的所有数据。入门您需要一个 IPinfo API 访问令牌,您可以通过在https://ipinfo.io/signup注册一个免费帐户来获取该令牌。免费计划每月限制为 50,000 个请求,并且不包括某些数据字段,例如 IP 类型和公司数据。要启用所有数据字段和额外的请求量,请参阅https://ipinfo.io/pricing点击此处查看 Java SDK 的 API 文档。安装Maven将这些值添加到您的 pom.xml 文件中依赖项<dependencies
资源推荐
资源详情
资源评论
收起资源包目录
IPinfo API 的官方 Java 库(IP 地理位置和其他类型的 IP 数据).zip (36个子文件)
pom.xml 6KB
.github
workflows
cd_maven.yml 1KB
标签.txt 31B
src
test
java
io
ipinfo
IPinfoTest.java 13KB
main
java
io
ipinfo
api
cache
NoCache.java 313B
SimpleCache.java 1KB
Cache.java 666B
IPinfo.java 17KB
errors
RateLimitedException.java 244B
ErrorResponseException.java 211B
context
Context.java 70KB
request
ASNRequest.java 1KB
MapRequest.java 1KB
IPRequest.java 7KB
BaseRequest.java 1KB
model
Company.java 754B
CountryCurrency.java 593B
CountryFlag.java 597B
Prefix.java 2KB
Abuse.java 1KB
Carrier.java 722B
Continent.java 559B
MapResponse.java 614B
Domains.java 627B
ASN.java 1KB
IPResponse.java 5KB
ASNResponse.java 3KB
Privacy.java 1KB
LICENSE 11KB
CHANGELOG.md 2KB
资源内容.txt 1KB
.gitignore 26B
README.md 9KB
scripts
ctags.sh 768B
deploy.sh 133B
deploy_docs.sh 306B
共 36 条
- 1
资源评论
徐浪老师
- 粉丝: 8084
- 资源: 7322
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLO图片标注xml转txt代码
- 安卓壳可以用于大屏开机打开网址
- paddlepaddle-gpu-2.5.2-cp38-cp38-win-amd64.whl
- Babel Street Analytics Java 客户端库.zip
- 图像处理中的White Patch算法来实现白平衡,MATLAB实现
- 在android studio 中使用jni来进行编程
- 开机自动启动VMWARE workstation16虚拟机
- Python 爬虫:把廖雪峰的教程转换成 PDF 电子书
- 2024 年 Java 开发人员路线图.zip
- matplotlib-3.7.5-cp38-cp38-win-amd64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功