| Crates.io | ip-lookup |
| lib.rs | ip-lookup |
| version | 0.1.3 |
| created_at | 2025-07-29 03:07:49.857422+00 |
| updated_at | 2025-08-01 15:55:01.727532+00 |
| description | A unified IP geolocation query library using multiple free public providers. |
| homepage | |
| repository | https://github.com/rfshub/ip-lookup |
| max_upload_size | |
| id | 1771851 |
| size | 57,217 |
A unified IP geolocation query library using multiple free public providers.
The ip-lookup crate provides a simple and unified interface to query IP geolocation information from multiple free public providers. It supports various providers like IpApi, IpInfo, IpSb, and more, allowing you to retrieve details such as country, city, coordinates, and network information for a given IP address.
Add the following to your Cargo.toml:
[dependencies]
ip-lookup = "0.1.0"
The crate provides functions to get the public IP address and query geolocation data using different providers. Below is an example of how to use the library:
use ip_lookup::{get_public_ip_addr, lookup, LookupProvider, LookupResult};
fn main() {
// Get the public IP address
if let Some(ip) = get_public_ip_addr() {
println!("Public IP: {}", ip);
}
// Query geolocation data using a specific provider
if let Some(result) = lookup(LookupProvider::IpApi) {
println!("Geolocation Data: {:?}", result);
}
// Iterate over all available providers
for provider in LookupProvider::all() {
if let Some(result) = lookup(*provider) {
println!("Provider: {:?}, Data: {:?}", provider, result);
}
}
}
The lookup function returns an Option<LookupResult>, where LookupResult contains detailed geolocation information. An example response might look like this:
{
"country": {
"city": "Singapore",
"code": "SG",
"zip": "535225",
"timezone": "Asia/Singapore"
},
"location": {
"latitude": 1.3371,
"longitude": 103.8946
},
"connection": {
"is_proxy": false,
"is_tor": false,
"is_crawler": false,
"is_datacenter": true,
"is_vpn": false
},
"network": {
"ip": "91.243.81.209",
"isp": "G-Core Labs S.A.",
"org": "G-Core Labs S.A.",
"asn": "AS199524 G-Core Labs S.A."
}
}
This project is licensed under the MIT License. See the LICENSE file for details.