ipapi
A Rust library to query IP addresses using the ipquery.io API.
Features
- Query details for a specific IP address
- Bulk query multiple IP addresses
- Fetch your own public IP address
Installation
To use this crate, add the following to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Usage
Query a Specific IP Address
The query_ip function retrieves information about a specific IP address, including its ISP, location, and risk data.
use query_ip;
use tokio;
async
Output Example
IPInfo {
ip: "8.8.8.8",
isp: Some(ISPInfo { asn: Some("AS15169"), org: Some("Google LLC"), isp: Some("Google LLC") }),
location: Some(LocationInfo {
country: Some("United States"),
country_code: Some("US"),
city: Some("Mountain View"),
state: Some("California"),
zipcode: Some("94035"),
latitude: Some(37.386),
longitude: Some(-122.0838),
timezone: Some("America/Los_Angeles"),
localtime: Some("2024-11-09T12:45:32"),
}),
risk: Some(RiskInfo {
is_mobile: Some(false),
is_vpn: Some(false),
is_tor: Some(false),
is_proxy: Some(false),
is_datacenter: Some(true),
risk_score: Some(0),
}),
}
Bulk Query Multiple IP Addresses
The query_bulk function allows you to query information for multiple IP addresses at once.
use query_bulk;
use tokio;
async
Output Example
IPInfo {
ip: "8.8.8.8",
...
}
IPInfo {
ip: "1.1.1.1",
...
}
Fetch Your Own Public IP Address
The query_own_ip function retrieves the public IP address of the current machine.
use query_own_ip;
use tokio;
async
Output Example
Your IP Address: 203.0.113.45
API Documentation
1. query_ip
Signature
pub async
Description
Fetches detailed information about a specific IP address, including its ISP, location, and risk information.
Parameters
ip: A string slice representing the IP address to query.
Returns
Ok(IPInfo)on success, containing details about the IP address.Err(reqwest::Error)if the network request or JSON deserialization fails.
Example
let result = query_ip.await?;
println!;
2. query_bulk
Signature
pub async
Description
Fetches information for multiple IP addresses at once. Useful for batch processing.
Parameters
ips: A slice of string slices representing the list of IP addresses to query.
Returns
Ok(Vec<IPInfo>)on success, containing details for each IP address.Err(reqwest::Error)if the network request or JSON deserialization fails.
Example
let ips = ;
let results = query_bulk.await?;
println!;
3. query_own_ip
Signature
pub async
Description
Fetches the public IP address of the current machine. Useful for determining your own IP address.
Returns
Ok(String)containing the public IP address.Err(reqwest::Error)if the network request fails.
Example
let ip = query_own_ip.await?;
println!;
Running Tests
To run the tests for this crate:
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.