SDKs
Markdown

Rust SDK

Official IPScope server-side client for Rust 1.75+ (2021 edition, Tokio async & blocking) (ipscope).

# Install

Install
cargo add ipscope

# Quickstart: single, batch & prefix lookups

Pass your API key explicitly or set IPSCOPE_KEY in your environment. Every lookup returns the canonical response schema with geo, network, connection, security and security_extensions.

Rust
use ipscope::{AsyncIpScopeClient, ClientConfig, LookupOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = ClientConfig::new(std::env::var("IPSCOPE_KEY")?);
    let client = AsyncIpScopeClient::new(config)?;

    // 1. Single IPv4 or IPv6 lookup
    let info = client.lookup_ip("198.51.100.7", None).await?;
    println!("{} {:?} VPN={}", info.ip, info.geo.country_code, info.security.is_vpn);

    // 2. Batch lookup (up to 100 IPs; deduplicates & reuses LRU cache)
    let ips = vec!["198.51.100.7".to_string(), "1.1.1.1".to_string()];
    let batch = client.lookup_batch(&ips, Some(&LookupOptions::default())).await?;
    println!("Resolved: {}", batch.count);

    // 3. Network CIDR prefix lookup
    let prefix = client.lookup_network("198.51.100.0/24").await?;
    println!("{} -> {:?}", prefix.queried_cidr, prefix.record.and_then(|r| r.organization));
    Ok(())
}
Responses
application/json

1. Single IPv4/IPv6 lookup response (GET /v1/ip/{ip})

{
  "ip": "198.51.100.7",
  "ip_version": 4,
  "matched_network": "198.51.100.0/24",
  "geo": {
    "country_code": "US",
    "declared_country_code": "US",
    "physical_country_code": "US",
    "is_virtual_location": false,
    "location_type": "physical",
    "confidence": 0.94,
    "subdivision": "Virginia",
    "city": "Ashburn",
    "postal_code": "20147",
    "latitude": 39.0438,
    "longitude": -77.4874,
    "accuracy_radius_km": 10,
    "timezone": "America/New_York"
  },
  "network": {
    "asn": 64501,
    "organization": "Example Cloud LLC"
  },
  "connection": {
    "connection_type": "hosting",
    "is_hosting": true,
    "is_residential": false,
    "is_mobile": false,
    "is_business": false
  },
  "security": {
    "is_vpn": true,
    "is_hosting": true,
    "is_tor_exit": false,
    "is_proxy": false,
    "anonymizer_type": "vpn",
    "confidence": 0.96,
    "reason_codes": [
      "vpn_handshake_confirmed",
      "datacenter_asn_range"
    ]
  },
  "security_extensions": {
    "abuse_velocity_score": 18,
    "is_known_scanner": false,
    "observation_recency_hours": 12,
    "anonymizer_reason": "vpn_handshake_confirmed",
    "threat_level": "medium",
    "abuse_velocity": "low",
    "confidence": 0.96
  },
  "dataset_version": "2026-10-27T00:00:00Z.crawl-1793088000000",
  "updated_at": "2026-10-27T00:00:00Z"
}
application/json

4. Network CIDR prefix lookup response (GET /v1/networks/{prefix}/{length})

{
  "queried_cidr": "198.51.100.0/24",
  "family": 4,
  "dataset_version": "2026-10-27T00:00:00Z.crawl-1793088000000",
  "record": {
    "prefix": "198.51.100.0/24",
    "family": 4,
    "asn": 64501,
    "organization": "Example Cloud LLC",
    "countryCode": "US",
    "city": "Ashburn",
    "locationType": "physical",
    "isVpn": true,
    "isHosting": true,
    "isTorExit": false,
    "isProxy": false,
    "anonymizerType": "vpn"
  }
}

# Architecture & runtime guarantees

  • Provides both AsyncIpScopeClient (Tokio + reqwest connection pool) and IpScopeClient (synchronous blocking client).
  • Strongly typed serde models (IpLookupResponse, GeoInfo, NetworkInfo, ConnectionInfo, SecurityInfo, SecurityExtensionsInfo).
  • Lock-striped O(1) bounded LRU cache and lookup_batch_chunked for zero-allocation chunked batch processing.
  • Typed IpScopeError enum distinguishing ApiError { status_code, code, message }, RateLimitExceeded, and TransportError.

# Reading local MMDB files

If you subscribe to a downloadable database, our .mmdb snapshots open directly in standard MaxMind DB readers with sub-microsecond in-memory lookups:

Rust (MMDB)
use maxminddb::Reader;
use std::net::IpAddr;

let reader = Reader::open_readfile("/var/lib/ipscope/ipscope-complete.mmdb")?;
let ip: IpAddr = "198.51.100.7".parse()?;
let record: serde_json::Value = reader.lookup(ip)?;

# Plain HTTP fallback

Need to call the REST API without installing a package? Use Rust’s standard HTTP client directly:

Rust (HTTP)
let res: serde_json::Value = reqwest::Client::new()
    .get("https://api.ipscope.io/v1/ip/198.51.100.7")
    .bearer_auth(std::env::var("IPSCOPE_KEY")?)
    .send()
    .await?
    .error_for_status()?
    .json()
    .await?;