Rust client for the ipdata.co IP geolocation and threat intelligence API.
Add to your Cargo.toml:
[dependencies]
ipdata = "0.1"let client = ipdata::IpData::new("your-api-key");
let info = client.lookup("8.8.8.8").await?;
println!("{} is in {}", info.ip, info.country_name.unwrap_or_default());let info = client.lookup_self().await?;Request only specific fields to reduce response size:
let info = client.lookup_fields("8.8.8.8", &["ip", "country_name", "asn"]).await?;let asn = client.lookup_field("8.8.8.8", "asn").await?;Look up to 100 IPs in a single request (requires a paid API key):
let results = client.bulk(&["8.8.8.8", "1.1.1.1"]).await?;
for info in &results {
println!("{} -> {}", info.ip, info.country_name.as_deref().unwrap_or("unknown"));
}Get specific data with strongly-typed return values:
let asn = client.asn("8.8.8.8").await?;
println!("ASN: {} ({})", asn.asn, asn.name);
let threat = client.threat("8.8.8.8").await?;
println!("Is threat: {}", threat.is_threat);
let tz = client.time_zone("8.8.8.8").await?;
println!("Timezone: {}", tz.name);
let currency = client.currency("8.8.8.8").await?;
println!("Currency: {} ({})", currency.name, currency.code);
let carrier = client.carrier("8.8.8.8").await?;
println!("Carrier: {}", carrier.name);Use the EU-specific endpoint backed by datacenters in Frankfurt, Paris, and Ireland:
let client = ipdata::IpData::eu("your-api-key");let client = ipdata::IpData::with_base_url("your-api-key", "https://custom-endpoint.example.com");match client.lookup("8.8.8.8").await {
Ok(info) => println!("{}", info.ip),
Err(ipdata::Error::Api { status, message }) => {
eprintln!("API error ({}): {}", status, message);
}
Err(ipdata::Error::InvalidIp(ip)) => {
eprintln!("Bad IP: {}", ip);
}
Err(e) => eprintln!("Error: {}", e),
}The main response type is IpInfo which includes:
- Geolocation:
city,region,country_name,country_code,continent_name,latitude,longitude,postal - ASN:
asn(struct withasn,name,domain,route,asn_type) - Company:
company(struct withname,domain,network,company_type) - Carrier:
carrier(struct withname,mcc,mnc) - Currency:
currency(struct withname,code,symbol,native,plural) - Time Zone:
time_zone(struct withname,abbreviation,offset,is_dst,current_time) - Organisation:
organisation(ISP / organization name) - Threat:
threat(struct withis_tor,is_vpn,is_proxy,is_anonymous,is_threat,is_bogon,blocklists,scores, and more) - Languages:
languages(vec ofLanguagewithname,native,code)
MIT