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));
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()),
}
}
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(""),
);
}
}