ipwhois-rust 1.2.0

Official Rust client for the ipwhois.io IP Geolocation API. Simple, supports single and bulk IP lookups.
Documentation
//! Run with: `cargo run --example defaults`
//!
//! If you make many requests with the same options, set them once on the
//! client. Per-call options always override the defaults.

use std::time::Duration;

use ipwhois::{IpWhois, Options};

#[tokio::main]
async fn main() {
    let ipwhois = IpWhois::with_key("YOUR_API_KEY")
        .with_language("en")
        .with_fields(["success", "country", "city", "flag.emoji", "connection.isp"])
        .with_security(true)
        .with_timeout(Duration::from_secs(8));

    // Both calls below will use lang=en, the field whitelist, and security=1.
    for ip in ["8.8.8.8", "1.1.1.1"] {
        match ipwhois.lookup(ip).await {
            Ok(info) => println!(
                "{}: {} / {} {}",
                ip,
                info.country.as_deref().unwrap_or(""),
                info.city.as_deref().unwrap_or(""),
                info.flag
                    .as_ref()
                    .and_then(|f| f.emoji.as_deref())
                    .unwrap_or(""),
            ),
            Err(e) => eprintln!("{}: {}", ip, e.message()),
        }
    }

    // One-off override — this single call uses German instead of English.
    if let Ok(info) = ipwhois
        .lookup_with("8.8.4.4", &Options::new().with_lang("de"))
        .await
    {
        println!(
            "8.8.4.4 (de): {} / {}",
            info.country.as_deref().unwrap_or(""),
            info.city.as_deref().unwrap_or(""),
        );
    }
}