Rust SDK · Feature

IP Geolocation in Rust

Turn any IP address into geolocation, network, and threat intelligence with one call. The lookup_ip method on the official ip-api-io client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the suspicious_factors flags used for fraud screening — in a single typed response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • A recent stable Rust toolchain with an async runtime (Tokio)
  • The ip-api-io crate added (cargo add ip-api-io)
  • A free ip-api.io API key
1

Geolocate one IP with lookup_ip

Pass any IPv4 or IPv6 address, or use lookup() to geolocate the caller's own IP. Nullable fields are Option<T> — match before use.

let client = Client::new(std::env::var("IP_API_IO_KEY")?);

let info = client.lookup_ip("8.8.8.8").await?;

println!("{}", info.ip);                       // "8.8.8.8"
if let Some(isp) = &info.isp {
    println!("{isp}");                         // "Google LLC"
}
if let Some(country) = &info.location.country {
    println!("{country}");                     // "United States"
}
println!("{}", info.suspicious_factors.is_datacenter); // true

Resolve the IP of the machine making the request by calling lookup():

let me = client.lookup().await?;
println!("{}", me.ip);
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to lookup_ip(ip) rather than relying on the socket address. See the SDK overview for an Axum handler example.
2

Geolocate up to 100 IPs with lookup_batch

Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK returns an Error if the slice is empty or longer than 100.

let batch = client
    .lookup_batch(&["8.8.8.8", "1.1.1.1", "9.9.9.9"])
    .await?;

println!("{}", batch.total_processed);    // 3
println!("{}", batch.successful_lookups); // 3
println!("{}", batch.failed_lookups);     // 0

for (ip, info) in &batch.results {
    println!("{ip} {}", info.suspicious_factors.is_vpn);
}
Reference

Response reference

lookup_ip resolves to a typed IpInfo. Nullable fields are Option<T>None for private or unrecognized addresses.

FieldTypeDescription
ipStringThe looked-up address
ispOption<String>Internet service provider
asnOption<String>Autonomous system the IP belongs to
locationLocationcountry, country_code, city, latitude, longitude, zip, timezone, local_time, local_time_unix, is_daylight_savings (nullable → Option)
suspicious_factorsSuspiciousFactorsis_proxy, is_vpn, is_tor_node, is_datacenter, is_spam, is_crawler, is_threat
FAQ

Frequently asked questions

How do I get the location of an IP address in Rust?

Add ip-api-io, construct a client with your API key, and .await client.lookup_ip(ip). The returned IpInfo has a location struct with country, city, latitude, longitude and timezone, plus a suspicious_factors struct with VPN/proxy/Tor flags.

How do I geolocate the caller's own IP?

Call client.lookup().await? with no IP argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.lookup_ip(ip) instead.

How do I look up many IP addresses at once?

Use client.lookup_batch(ips).await? with up to 100 addresses in one request. It returns results (a HashMap<String, IpInfo>) plus total_processed, successful_lookups and failed_lookups, and errors if the slice is empty or longer than 100.

Why are some fields Option?

Nullable location fields such as country and city are Option<String> because they're absent for private ranges or unrecognized addresses — match or if let Some(..) before use. Boolean flags like is_vpn are plain bool.

Start building with the ip-api.io Rust SDK

Run cargo add ip-api-io, drop in your free API key, and ship in minutes — one async client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io crate is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub