| Crates.io | asninfo |
| lib.rs | asninfo |
| version | 0.4.3 |
| created_at | 2025-02-21 20:22:37.387871+00 |
| updated_at | 2025-10-30 03:37:15.810063+00 |
| description | A utility tool to export ASN information to JSON files. |
| homepage | |
| repository | https://github.com/bgpkit/asninfo |
| max_upload_size | |
| id | 1564668 |
| size | 102,031 |
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.
cargocargo install asninfo
homebrew on macOSbrew install bgpkit/tap/asninfo
cargo-binstallcargo install cargo-binstall
cargo binstall asninfo
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)
asninfo generate ./asninfo.jsonl
# same as "asninfo generate"
asninfo generate ./asninfo.csv
asninfo generate -s ./asninfo.json
export ASNINFO_UPLOAD_PATH="r2://my-bucket/asn/asninfo.jsonl"
export AWS_REGION="auto" # for Cloudflare R2
export AWS_ENDPOINT="https://<account>.r2.cloudflarestorage.com"
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
asninfo generate ./asninfo.jsonl
Start the server:
asninfo serve --bind 0.0.0.0:8080 --refresh-secs 21600
GET /health
GET /lookup?asns=AS1,AS2,...[&legacy=true]
POST /lookup
Default response (full schema plus country_name):
[
{
"asn": 13335,
"name": "CLOUDFLARENET",
"country": "US",
"country_name": "United States",
"as2org": {
"org_id": "CLOUD14-ARIN",
"org_name": "Cloudflare, Inc.",
"name": "CLOUDFLARENET",
"country": "US"
},
"hegemony": {
"asn": 13335,
"ipv4": 0.0018,
"ipv6": 0.0084
},
"peeringdb": {
"asn": 13335,
"name": "Cloudflare",
"aka": "",
"name_long": "",
"website": "https://www.cloudflare.com",
"irr_as_set": "AS13335:AS-CLOUDFLARE"
},
"population": {
"user_count": 10,
"sample_count": 127,
"percent_global": 0.0,
"percent_country": 0.02
}
}
]
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.
# GET
curl 'http://localhost:8080/lookup?asns=13335,15169'
# POST
curl -X POST 'http://localhost:8080/lookup' \
-H 'Content-Type: application/json' \
-d '{"asns":[13335,15169]}'
[
{
"as2org": {
"country": "US",
"name": "CLOUDFLARENET",
"org_id": "CLOUD14-ARIN",
"org_name": "Cloudflare, Inc."
},
"asn": 13335,
"country": "US",
"country_name": "United States",
"hegemony": {
"asn": 13335,
"ipv4": 0.0017993252336435785,
"ipv6": 0.008380104743151566
},
"name": "CLOUDFLARENET",
"peeringdb": {
"aka": "",
"asn": 13335,
"irr_as_set": "AS13335:AS-CLOUDFLARE",
"name": "Cloudflare",
"name_long": "",
"website": "https://www.cloudflare.com"
},
"population": {
"percent_country": 0.02,
"percent_global": 0.0,
"sample_count": 127,
"user_count": 10
}
},
{
"as2org": {
"country": "US",
"name": "GOOGLE",
"org_id": "GOGL-ARIN",
"org_name": "Google LLC"
},
"asn": 15169,
"country": "US",
"country_name": "United States",
"hegemony": {
"asn": 15169,
"ipv4": 0.0072255134909779304,
"ipv6": 0.002685539203529714
},
"name": "GOOGLE",
"peeringdb": {
"aka": "Google, YouTube (for Google Fiber see AS16591 record)",
"asn": 15169,
"irr_as_set": "RADB::AS-GOOGLE",
"name": "Google LLC",
"name_long": "",
"website": "https://about.google/intl/en/"
},
"population": {
"percent_country": 0.01,
"percent_global": 0.0,
"sample_count": 740,
"user_count": 521
}
}
]
When exporting CSV (or using --simplified), the schema is:
asn,as_name,org_id,org_name,country_code,country_name,data_source
Notes:
Required for S3/R2 upload (when ASNINFO_UPLOAD_PATH is set):
Optional:
.env files are supported and loaded automatically when present.
A minimal container image can be built using the provided Dockerfile:
docker build -t asninfo .
# run generator, mounting a host directory for output
docker run --rm -v "$PWD:/out" asninfo generate /out/asninfo.jsonl
# run HTTP server on port 8080
docker run --rm -p 8080:8080 asninfo serve --bind 0.0.0.0:8080
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
docker run --rm \
--env-file ./.env \
-v "$PWD:/out" \
asninfo generate /out/asninfo.jsonl
# server example with env-file
docker run --rm \
--env-file ./.env \
-p 8080:8080 \
asninfo serve --bind 0.0.0.0:8080