8个版本
0.3.2 | 2024年4月25日 |
---|---|
0.3.1 | 2024年4月25日 |
0.2.2 | 2024年4月19日 |
0.1.1 | 2024年4月3日 |
0.1.0 | 2024年3月29日 |
在 网络编程 中排名第 1042
每月下载量 100
用于 auto-timezone-tool
740KB
3.5K SLoC
🔎 公共IP地址查找和地理位置信息
public-ip-address
是一个简单的Rust库,可以从十几个不同服务中执行公共IP查找。
它提供了一个统一的接口,用于从多个提供商获取公共IP地址和地理位置信息。支持任意IP地址查找和某些提供商的API密钥访问。该库提供了异步和阻塞接口,以便与其他 async
代码库轻松集成。
此外,库还包括缓存功能,以提高重复查找的性能并最小化达到速率限制阈值。当通过功能标志启用时,可以加密缓存文件以提供额外的隐私。
用法
将以下内容添加到您的 Cargo.toml
文件中
[dependencies]
public-ip-address = { version = "0.3" }
# with cache encryption enabled
public-ip-address = { version = "0.3", features = ["encryption"] }
# with `async` disabled
public-ip-address = { version = "0.3", features = ["blocking"] }
示例
使用此库的最简单方法是调用 perform_lookup()
函数,该函数返回一个包含 LookupResponse
的 Result
。
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Perform my public IP address lookup
let result = public_ip_address::perform_lookup(None).await?;
println!("{}", result);
Ok(())
}
启用 blocking
接口
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// Perform my public IP address lookup
let result = public_ip_address::perform_lookup(None)?;
println!("{}", result);
Ok(())
}
更多示例可以在 examples
目录中找到。并使用以下命令运行它们
cargo run --example <example_name>
启用 blocking
功能运行示例
cargo run --example <example_name> --features blocking
提供商
提供商 | URL | 速率限制 | API密钥 | 目标查找 |
---|---|---|---|---|
FreeIpApi | https://freeipapi.com | 60 / 分钟 | ✔️ | ✔️ |
IfConfig | https://ifconfig.co | 1 / 分钟 | ✔️ | |
IpInfo | https://ipinfo.io | 50000 / 月份 | ✔️ | ✔️ |
MyIp | https://my-ip.io | ? / 天 | ️ | ️ |
IpApiCom | https://ip-api.com | 45 / 分钟 | ✔️ | |
IpWhoIs | https://ipwhois.io | 10000 / 月份 | ️ | ✔️ |
IpApiCo | https://ipapi.co | 30000 / 月份 | ✔️ | |
IpApiIo | https://ip-api.io | ? / 天 | ✔️ | ✔️ |
IpBase | https://ipbase.com | 每小时10次 | ✔️ | ✔️ |
IpLocateIo | https://iplocate.io | 每天50次 | ✔️ | ✔️ |
IpLeak | https://ipleak.net | ? / 天 | ️ | ✔️ |
Mullvad | https://mullvad.net | ? / 天 | ️ | ️ |
AbstractApi | https://abstractapi.com | 每天1000次 | ✔️ | ✔️ |
IpGeolocation | https://ipgeolocation.io | 每天1000次 | ✔️ | ✔️ |
IpData | https://ipdata.co | 每天1500次 | ✔️ | ✔️ |
Ip2Location | https://ip2location.io | 每天500次(含键30000/月) | ✔️ | ✔️ |
MyIpCom | https://myip.com | 无限 | ️ | ️ |
GetJsonIp | https://getjsonip.com | 无限 | ️ | ️ |
Ipify | https://www.ipify.org | 无限 | ️ | ️ |
路线图
- 初始发布
- 添加更多提供商
- 添加对具有API密钥的额外提供商的支持
- 添加反向查找功能
- 添加异步和同步接口支持
- 批量查找
- 离线反向查找
许可
许可方式如下
- Apache License,版本2.0(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可(LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
欢迎贡献!请提交一个拉取请求。
支持
如果您遇到任何问题或有任何疑问,请在GitHub仓库中打开一个问题。
依赖关系
~4-19MB
~241K SLoC