Prerequisites
- A stable Rust toolchain with
ip-api-ioadded - A free ip-api.io API key
Autonomous system with asn
Returns the ASN, owning organization, network range, and country for an IP — and
whether it belongs to a datacenter. Nullable fields are Option<T>.
let client = Client::new(std::env::var("IP_API_IO_KEY")?);
let asn = client.asn("8.8.8.8").await?;
if let Some(number) = asn.asn {
println!("{number}"); // 15169
}
if let Some(org) = &asn.organization {
println!("{org}"); // "Google LLC"
}
println!("{}", asn.is_datacenter); // true Domain registration with whois
WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.
let whois = client.whois("example.com").await?;
if let Some(registrar) = whois.registrar.as_ref().and_then(|r| r.name.as_ref()) {
println!("{registrar}");
}
if let Some(registered_on) = &whois.registered_on {
println!("{registered_on}"); // "1995-08-14"
}
println!("{:?}", whois.name_servers); DNS with reverse_dns, forward_dns & mx_records
Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.
let rdns = client.reverse_dns("8.8.8.8").await?;
if let Some(hostname) = &rdns.hostname {
println!("{hostname}"); // "dns.google"
}
let fdns = client.forward_dns("dns.google").await?;
for record in &fdns.addresses {
println!("{} {} {}", record.r#type, record.address, record.ttl); // "A" "8.8.8.8" 300
}
let mx = client.mx_records("example.com").await?;
for record in &mx.mx_records {
println!("{} {} {}", record.priority, record.hostname, record.ttl);
}