InternetData Rust Client Library
The official Rust client library for the InternetData API.
It tells you what every InternetData database says about an IP address, an AS or a domain, and downloads the licensed databases themselves.
Getting Started
Requires Rust 1.85 or newer. Everything is async and runs on tokio.
Usage
No API key needed to start. Unlimited, the free plan, answers the Tor and relay flags, InternetData's own flags such as is_anycast and is_web, location to the country, asn, company, hostname and the abuse email, limited per address per minute, with a key or without one.
use Client;
let client = new?;
let result = client.lookup.await?;
println!; // AT
println!; // M247 Europe SRL
println!; // false
With an API key
Every paid plan answers every field: is_vpn, is_hosting, is_cdn and the four proxy flags as well, the detail behind each flag, the city-level location, whois and rwhois. A free account tries every field, 100 lookups a day. Create a key in the console, then pass it in:
let client = builder
.api_key
.build?;
let result = client.lookup.await?;
println!; // Some(true), on a paid plan
println!; // Some("Vienna"), on a paid plan
if let Some = result.vpn.as_deref
Every setting has a default, and Client::builder() is where you change one:
let client = builder.api_key.concurrency.retries.build?;
Each attempt at a request gives up after 30 seconds, and timeout changes that. A database download isn't bound by it, since a large one runs for minutes:
use Duration;
let client = builder.api_key.timeout.build?;
Your own address
let result = client.my_ip.await?;
println!; // the address we saw this call come from
Same answer lookup would give for that address, and the same cost against your allowance. It is deliberately not cached: which address you are is the whole question, and a machine that moves between networks would otherwise be told where it used to be.
Your plan and usage
let acct = client.my_entitlement.await?;
println!; // free
println!; // Unlimited, the name to show
println!; // 42
println!; // when the allowance resets
Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the UTC day on the free plan; it is the same number a lookup is gated on. hard_limit is None on an uncapped plan, which is not the same as zero.
my_ip_with and my_entitlement_with take this call's own retry budget and timeout, the same as lookup_with.
Batch lookup
Look up many addresses at once. Bogons and cached answers are handled locally, and everything else goes to the batch endpoint in chunks of up to 1000 addresses, in parallel. The batch endpoint needs a paid plan:
use BatchOptions;
let results = client
.lookup_batch
.await;
for in &results
Results are keyed by address and in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
There's no limit on how many addresses you pass. How many chunks are in flight at once, how many times a failed chunk is retried, and how long each attempt may take are configurable per call:
let results = client
.lookup_batch
.await;
AS and domain lookups
let asn = client.lookup_asn.await?;
println!; // M247 Europe SRL ripe
let domain = client.lookup_domain.await?;
println!; // true
lookup takes an address alone and refuses an AS or a domain before sending it. Neither of these is cached or batched, and lookup_asn_with and lookup_domain_with take the call's own retry budget and timeout.
Caching
Address lookups are cached by default, so repeat lookups of the same address are free:
let client = new?;
let result = client.lookup.await?;
println!; // AT, API request
let result2 = client.lookup.await?;
println!; // AT, no API request, result was cached
You can change the default cache variables (max size, TTL, etc) on initialization, or even disable it:
use Duration;
let client = builder.cache.build?;
let client_no_cache = builder.no_cache.build?;
Private and reserved addresses
Private, loopback, link-local, documentation and multicast addresses (and their IPv6 equivalents, including the 6to4 and Teredo ranges) aren't on the public internet, so there's nothing to look up. The library answers them locally, so they cost no request and no quota:
let result = client.lookup.await?;
result.is_bogon; // true, this answer was computed rather than served
result.is_tor; // false
Because the answer is computed rather than served, it always carries every field, whatever plan you are on. Do not read your plan's shape off a private address.
The check is available on the client, which is handy when your inputs are addresses anyway:
client.is_bogon; // true
client.is_bogon; // false
It is also callable on its own, if you want it without a client:
is_bogon; // true
Errors
Failures return an internetdata::Error carrying a kind() and a retryable() flag:
use ErrorKind;
match client.lookup.await
kind() is one of BadRequest, Unauthorized, Forbidden, RateLimited, QuotaExceeded, ServerError, Network or Io, the last of which is a database transfer that could not be written or that ended early. message() carries the API's own reason, such as invalid API key from a lookup or NOT_LICENSED from a database call.
Note that RateLimited and QuotaExceeded both arrive as HTTP 429 and are not the same thing. A rate limit carries Retry-After, and retrying after it works; one without it is QuotaExceeded. The library retries rate limits for you, but never QuotaExceeded. The API itself always sends Retry-After with a 429, so that one comes from something in between, such as a proxy; a paid key past its overage cap gets cap_reached instead.
Database downloads
The databases need an API key carrying the db.download scope. They hang off client.database(), which is where the sibling VPNDetection crate keeps the same seven calls:
for database in client.database.list.await?
The catalog
list() answers database FAMILIES. A license covers the family, while a download names one of its versions, so the ID you pass to download, checksums and metadata comes from versions:
for database in client.database.list.await?
standing is Licensed for a live grant, Expired for one whose term has ended, and Unlicensed for a database published but never bought, so you can see what else exists without asking us. license_type says what your license lets you do with the data, and is None when there is no license.
Standing, LicenseType, DatabaseFormat and a download's Outcome are #[non_exhaustive]: a value we add after your release comes back as Other, carrying it as we sent it, rather than failing the call, so give a match on one a _ arm. as_str() and {} print the value as the API spells it.
What is inside a database
metadata carries the column schema, a few real rows, the row count and the size of each artifact, without downloading anything. Poll it to decide whether today's build is worth fetching, and read size to know what a transfer will cost before you start it:
let meta = client.database.metadata.await?;
println!; // 1234 rows, built 2026-09-04
println!; // Some(760)
for column in &meta.schema
Downloading
use DatabaseFormat;
let written = client.database.download.await?;
download streams to disk through a neighboring .part file, so nothing bigger than a chunk is ever held in memory and a transfer that dies half way neither leaves a truncated file nor replaces the copy already on disk.
let raw = client.database.download_bytes.await?;
download_bytes holds the whole file in memory. The catalog spans seven orders of magnitude, from a few hundred bytes to several gigabytes, so check metadata first for anything you have not measured.
let url = client.database.download_url.await?;
download_url hands back the time-limited link the API redirects to, so you can run the transfer yourself with whatever tool you like. It authorizes itself and carries none of your credentials, so it is safe to pass on. The link only has to be valid when a transfer starts, so one already running isn't cut off when it lapses.
Each of the three downloads the build that is live unless you name one. A database.updated webhook names the build it announces and carries its sha256, so a receiver that downloads after the next publish asks for that build, through the _with form of the call, to get the file the hash is of:
use DownloadOptions;
let options = new.build;
let written = client.database.download_with.await?;
A build is kept 7 days. Past that the call fails as a BadRequest with the message BUILD_GONE, and downloading without one fetches the live build.
Not every database is built in every format, which is why versions lists the ones it has. Asking for another is a BadRequest, not a gap.
Verifying a download
let sums = client.database.checksums.await?;
println!;
Download history
downloads lists your organization's recent attempts, newest first, refusals included. A denial is what answers "it stopped working", and its absence answers nothing:
for attempt in client.database.downloads.await?
Pass None for the API's own default of 50. Anything above 200 is clamped.
Sign in with OAuth (device flow)
A program running on the person's own machine can let them sign in with a browser and pick one of their API keys, instead of asking them to paste it:
use ;
let client = new?;
let scope = new.scope;
let device = client.oauth.device_authorization_with.await?;
println!;
let token = client.oauth.poll_device_token.await?;
let Some = token.apikey else ;
let keyed = builder.api_key.build?;
A denied sign-in fails with OauthError::AccessDenied and a code that ran out with OauthError::ExpiredToken. Client IDs are issued on request from support@internetdata.io, and client.oauth().revoke("your-client-id", &refresh_token) signs the machine out again.
Sign in with OAuth (authorization code)
An app that can take a browser redirect signs the person in there instead, with a PKCE pair made for that one sign-in:
use ;
let client = new?;
let redirect_uri = "http://127.0.0.1:8765/callback";
let pkce = client.oauth.create_pkce?;
let opts = new.scope.state;
let url =
client.oauth.authorization_url_with?;
// Open url in the browser. Its redirect to redirect_uri carries code and state.
let token = client
.oauth
.exchange_authorization_code
.await?;
Check that state came back as you sent it before you exchange code, which works once. The client ID can also be the https URL of a client metadata document your app serves, and such an app is never handed a key, so token.apikey stays None.
Register a client
An app with no client ID, and no client metadata document to use as one, registers itself, then signs in with the client_id it gets back as the client ID for authorization_url and exchange_authorization_code:
let client = new?;
let opts = new.client_name;
let registration =
client.oauth.register_with.await?;
Each redirect URI must be https on a public host name, or http on a loopback address, which then matches any port. Nothing is kept until a person approves the client, so an app with no client ID saved can simply register again.
TLS backends
rustls is the default, so the crate builds with no system libraries at all. If you would rather link the platform's TLS, or you already depend on reqwest with its own defaults and want one backend rather than two:
= { = "3", = false, = ["native-tls"] }
Calling from synchronous code
There is no blocking facade, on purpose: reqwest::blocking builds its own runtime and panics when constructed inside one, so a facade would fail for exactly the callers most likely to reach for it. If you have no runtime, make the cost visible instead:
let runtime = new?;
let client = new?;
let result = runtime.block_on?;
Absent is not false
Unlimited leaves out is_vpn, is_hosting, is_cdn and the four proxy flags, the detail behind every flag but Tor's and relay's, and the paid members of the shared objects, location.city and asn.rpki_status among them; a free-plan key's answer carries trial_expired, true once its daily trial is spent. A paid key's carries cap_reached, true once its organization's overage cap is reached, when the answer has Unlimited's fields and isn't billed. Every member a plan can leave out is an Option, because your key decides which of them the API sends. None means "not in your plan", which is not the same answer as Some(false), which means "checked, and no".
result.is_hosting.unwrap_or; // when you only want the flag
result.is_hosting.is_none; // on Unlimited: not in your plan
result.trial_expired == Some; // a free-plan key's daily trial is spent
result.cap_reached == Some; // a paid key is past its overage cap
Other Libraries
There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.
About InternetData
Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, answered by the API or licensed as files you download and query yourself.
License
This project is licensed under the MIT License.