use ipwhois::{IpWhois, Options};
#[tokio::main]
async fn main() {
let ipwhois = IpWhois::new();
match ipwhois.lookup("8.8.8.8").await {
Ok(info) => {
println!(
"{} {} ({}, {})",
info.ip.as_deref().unwrap_or(""),
info.flag
.as_ref()
.and_then(|f| f.emoji.as_deref())
.unwrap_or(""),
info.country.as_deref().unwrap_or("unknown"),
info.city.as_deref().unwrap_or("unknown"),
);
}
Err(e) => {
eprintln!("Lookup failed: {}", e.message());
std::process::exit(1);
}
}
if let Ok(me) = ipwhois.lookup_self().await {
println!(
"My IP: {} — {}",
me.ip.as_deref().unwrap_or(""),
me.country.as_deref().unwrap_or(""),
);
}
let paid = IpWhois::with_key("YOUR_API_KEY");
let opts = Options::new()
.with_lang("en") .with_fields(["success", "country", "city", "connection.isp", "flag.emoji"])
.with_security(true) .with_rate(true);
match paid.lookup_with("1.1.1.1", &opts).await {
Ok(info) => println!("{:#?}", info),
Err(e) => eprintln!("error ({}): {}", e.error_type(), e.message()),
}
}