9 breaking releases

0.13.0 Jan 29, 2025
0.11.3 Nov 24, 2024
0.8.0 Apr 10, 2024
0.7.0 Oct 4, 2023
0.1.0 Feb 16, 2020

#2112 in Network programming

Download history 10/week @ 2024-10-16 6/week @ 2024-10-30 7/week @ 2024-11-06 2/week @ 2024-11-13 297/week @ 2024-11-20 84/week @ 2024-11-27 13/week @ 2024-12-04 11/week @ 2024-12-11 101/week @ 2025-01-22 186/week @ 2025-01-29

287 downloads per month
Used in 3 crates (via citadel_wire)

MIT/Apache

40KB
290 lines

async_ip

An asynchronous client used to obtain one's global Ipv6 or Ipv4 address


lib.rs:

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.

Dependencies

~1–12MB
~143K SLoC