ASN Information Tool (exporter and HTTP API)
Export up-to-date ASN information to JSON, JSONL, or CSV files, and optionally upload to an S3-compatible target. You can also run a lightweight HTTP API server to perform ASN info lookups.
- Export formats: JSON, JSONL, CSV (CSV uses a simplified schema)
- Optional upload to S3/R2 via environment variables (no CLI flag needed)
- HTTP API with GET/POST lookup endpoints and CORS enabled
- .env files supported via dotenv
Install
Using cargo
Using homebrew on macOS
Using cargo-binstall
Commands
The CLI provides two subcommands: generate and serve.
asninfo generate [OPTIONS] [PATH]
Options:
-s, --simplified Export simplified fields (implied for .csv)
Arguments:
[PATH] Export data path (default: ./asninfo.jsonl)
Format is inferred from file extension: .json, .jsonl, or .csv
asninfo serve [OPTIONS]
Options:
-b, --bind <ADDR:PORT> Bind address (default: 0.0.0.0:8080)
--refresh-secs <SECS> Background refresh interval in seconds (default: 21600)
--simplified Use simplified mode (skip heavy datasets)
Examples
- Export JSONL with full fields:
# same as "asninfo generate"
- Export CSV (simplified schema is implied):
- Export simplified JSON (smaller payload):
- Upload automatically to S3/R2 by setting environment variables:
# for Cloudflare R2
HTTP API
Start the server:
- Background updater refreshes the in-memory dataset every refresh-secs seconds (minimum 3600).
- CORS is enabled for all origins.
- Simplified mode reduces memory footprint by skipping heavy datasets (population, hegemony, PeeringDB).
- The maximum number of ASNs per request is limited by the environment variable ASNINFO_MAX_ASNS (default 100).
Endpoints
-
GET /health
- Returns status and metadata, including updatedAt timestamp.
-
GET /lookup?asns=AS1,AS2,...[&legacy=true]
- Query parameter asns is a comma-separated list of ASNs.
- Optional legacy=true to return a legacy array of objects instead of the structured response.
-
POST /lookup
- JSON body: { "asns": [number, ...] }
- Note: legacy=true is only supported on GET /lookup.
Responses
Default response (full schema plus country_name):
Note: When the server runs with --simplified, heavy datasets (population, hegemony, PeeringDB) are omitted and will be null in responses.
Legacy response (when legacy=true) returns an array of objects compatible with the previous consumer format.
Example requests
# GET
# POST
CSV simplified schema
When exporting CSV (or using --simplified), the schema is:
asn,as_name,org_id,org_name,country_code,country_name,data_source
Notes:
- country_name is looked up from country_code where available.
- data_source is reserved for future use.
Environment variables
Required for S3/R2 upload (when ASNINFO_UPLOAD_PATH is set):
- AWS_REGION — for Cloudflare R2, use "auto"
- AWS_ENDPOINT — S3-compatible endpoint URL
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- ASNINFO_UPLOAD_PATH — destination like s3://bucket/key or r2://bucket/key
Optional:
- ASNINFO_HEARTBEAT_URL — HTTP/HTTPS URL to request after a successful upload (used as a heartbeat)
- ASNINFO_MAX_ASNS — maximum ASNs per lookup request for the HTTP API (default: 100)
- PEERINGDB_API_KEY — used by dependencies to access PeeringDB API (avoids rate limits)
.env files are supported and loaded automatically when present.
Docker
A minimal container image can be built using the provided Dockerfile:
# run generator, mounting a host directory for output
# run HTTP server on port 8080
Using a local env file (.env)
The image supports environment variables for uploads and server limits. You can pass your local .env to the container
using Docker's --env-file:
# pass variables from ./.env to the container environment
# works for both generate and serve
# server example with env-file