ipscanner-rust
Official Rust client for the IPScanner API.
Install
The crate is imported as ipscanner. It is async and runs on Tokio.
Quick start
async
Get a key at https://ipscanner.io. Full API reference: https://ipscanner.io/api-documentation.
Usage
IP
use HistoryParams;
let result = client.ip.lookup.await?;
let vpn = client.ip.vpn.await?;
let proxy = client.ip.proxy.await?;
let geo = client.ip.geo.await?;
let asn = client.ip.asn.await?;
let whois = client.ip.whois.await?;
let history = client.ip.history.await?;
let demo = client.ip.demo.await?;
let me = client.ip.myip.await?;
demo and myip work without a key.
vpn_provider is the VPN brand (such as Mullvad) when known; provider is the network owner. On the Free plan, premium fields (purity, provider, vpn_provider, precise geo, bulk score/grade/verdict) are null, and the response lists them in locked with plan_required set to Starter.
Bulk
use StreamExt;
use BulkRequest;
let report = client.bulk.check.await?;
let mut stream = client.bulk.stream.await?;
while let Some = stream.next.await
The stream reads NDJSON with a 5 minute timeout. BulkEvent::complete() is true only when every unique IP was processed.
Agentscan
use ;
let check = client.agentscan.check.await?;
let batch = client.agentscan.batch.await?;
let verified = client.agentscan.verify.await?;
let allowlist = client.agentscan.allowlist.await?;
let me = client.agentscan.self_check.await?;
Edge
use EdgeCheckRequest;
let res = client.edge.check.await?;
println!;
Sites
let policy = client.sites.policy.await?;
Gate
use GateVerifyRequest;
let res = client.gate.verify.await?;
if res.action == "block"
gate().verify sends the site secret, not the API key, and is never retried.
Provenance
use ;
let attestation = client.provenance.check.await?;
let chain = client.provenance.chain.await?;
let ok = client.provenance.verify.await?;
let anchored = client.provenance.verify_anchored.await?;
let jurisdictions = client.provenance.jurisdictions.await?;
let csv: String = client.provenance.export.await?;
Account
let limits = client.account.limits.await?;
let usage = client.account.usage.await?;
ASN directory
use AsnTopParams;
let top = client.asn_directory.top.await?;
let found = client.asn_directory.search.await?;
let google = client.asn_directory.get.await?;
Crawlers
let crawlers = client.crawlers.list.await?;
Errors
Every call returns Result<T, ipscanner::Error>:
| Variant | When |
|---|---|
Error::Authentication(ApiError) |
401 or 403 |
Error::NotFound(ApiError) |
404 |
Error::RateLimit(Box<RateLimitError>) |
429 |
Error::Api(ApiError) |
any other error status |
Error::Timeout |
the request timed out |
Error::Http(reqwest::Error) |
connection or transport failure |
Error::Decode(serde_json::Error) |
unexpected response body |
ApiError has status, code, message, details and the raw body. RateLimitError adds reason, retry_after, reset_at, limit, usage, remaining, needed, plan, upgrade_url and the parsed X-RateLimit-* headers.
match client.ip.lookup.await
GET requests are retried up to 2 times on connection errors and 502, 503 and 504. POST requests and 429 responses are never retried.
Configuration
use Duration;
let client = builder
.api_key
.base_url
.timeout
.max_retries
.build?;
Client::from_env() reads IPSCANNER_API_KEY and IPSCANNER_API_URL. A client without a key can call the keyless routes. Pass your own reqwest::Client with .http_client(..).
Licence
MIT