Expand description
§Async IP Resolution
A lightweight, asynchronous client for obtaining global IPv4 and IPv6 addresses. This crate provides reliable IP address resolution using multiple fallback services and concurrent requests for improved reliability.
§Features
- Async IP address resolution
- Support for both IPv4 and IPv6
- Multiple fallback services
- Concurrent resolution for improved reliability
- Internal IP address detection
- WebAssembly support
- Custom HTTP client support
§Usage
use async_ip::get_all;
use citadel_io::tokio;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), async_ip::IpRetrieveError> {
// Get both internal and external IP addresses
use reqwest::Client;
let ip_info = get_all::<Client>(None).await?;
println!("External IPv6: {:?}", ip_info.external_ipv6);
println!("Internal IPv4: {:?}", ip_info.internal_ip);
Ok(())
}
§Advanced Usage
use async_ip::{get_all_multi_concurrent, get_default_client};
use citadel_io::tokio;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), async_ip::IpRetrieveError> {
// Use multiple services concurrently with a custom client
let client = get_default_client();
let ip_info = get_all_multi_concurrent(Some(client)).await?;
println!("External IPs: {:?}", ip_info);
Ok(())
}
§WebAssembly Support
When compiled with the wasm
target, this crate uses a lightweight HTTP client
suitable for WebAssembly environments. The functionality remains the same, but
some features (like internal IP detection) may be limited.
§Error Handling
The crate uses a custom IpRetrieveError
type that wraps various error
conditions that may occur during IP resolution, including network errors
and parsing failures.
Structs§
- IpAddress
Info - All the ip addr info for this node
Enums§
- IpRetrieve
Error - The default error type for this crate
Traits§
- Async
Http GetClient - An async http client
Functions§
- get_all
- Returns all possible IPs for this node
- get_
all_ from - Gets IP info concurrently using custom multiple internal sources
- get_
all_ multi_ concurrent - Gets IP info concurrently using default multiple internal sources
- get_
all_ multi_ concurrent_ from - Uses multiple url addrs to obtain the information
- get_
default_ client - Returns a default client
- get_
internal_ ip - Gets the internal IP address using DNS
- get_
internal_ ipv4 - Returns the internal ipv4 address of this node
- get_
ip_ from - Asynchronously gets the IP address of this node. If
prefer_ipv6
is true, then the client will attempt to get the IP address; however, if the client is using an IPv4 address, that will be returned instead.