A simple Python CLI + library for looking up ASNs by IP or AS number. Uses BBOT.IO API.
Project description
ASNDB
A simple Python CLI + library for instant lookup of ASN data by IP address, AS number, or organization. Uses BBOT.IO API (asndb.api.bbot.io).
ASNs are automatically cached for instant lookups and minimal network traffic.
Installation
pip install asndb
# or using uv
uv add asndb
Usage (CLI)
Note: To avoid rate limits, export your BBOT.IO API key as an environment variable:
export BBOT_IO_API_KEY=<your_api_key>
IP Lookup
asndb ip 1.1.1.1
Output:
{
"asn": 13335,
"asn_name": "CLOUDFLARENET",
"country": "US",
"ip": "1.1.1.1",
"org": "Cloudflare, Inc.",
"org_id": "CLOUD14-ARIN",
"rir": "ARIN",
"subnets": [
"1.0.0.0/24",
"1.0.1.0/24"
]
}
AS Number Lookup
asndb asn 13335
Output:
{
"asn": 13335,
"asn_name": "CLOUDFLARENET",
"country": "US",
"ip": "1.1.1.1",
"org": "Cloudflare, Inc.",
"org_id": "CLOUD14-ARIN",
"rir": "ARIN",
"subnets": [
"1.0.0.0/24",
"1.0.1.0/24"
]
}
Organization Lookup
# Look up an organization
asndb org CLOUD14-ARIN
Output:
{
"asns": [
13335,
14789,
395747,
394536
]
}
CLI Help
$ uv run asndb --help
Usage: asndb [OPTIONS] COMMAND [ARGS]...
╭─ Options ──────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or │
│ customize the installation. │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────╮
│ ip Lookup ASN by IP address │
│ asn Lookup ASN by AS number │
│ org Get all the ASNs for an organization, by its registered organization ID, e.g. │
│ GOGL-ARIN │
╰────────────────────────────────────────────────────────────────────────────────────────────╯
Usage (Python)
from asndb import ASNDB
# Create a new ASNDB client
asndb = ASNDB()
# Look up an IP address
asn = asndb.lookup_ip_sync("1.1.1.1")
# {
# "asn": 13335,
# "asn_name": "CLOUDFLARENET",
# "country": "US",
# "ip": "1.1.1.1",
# "org": "Cloudflare, Inc.",
# "org_id": "CLOUD14-ARIN",
# "rir": "ARIN",
# "subnets": [
# "1.0.0.0/24",
# "1.0.1.0/24"
# ]
# }
# Look up an AS number
asn = asndb.lookup_asn_sync(13335)
# {
# "asn": 13335,
# "asn_name": "CLOUDFLARENET",
# "country": "US",
# "ip": "1.1.1.1",
# "org": "Cloudflare, Inc.",
# "org_id": "CLOUD14-ARIN",
# "rir": "ARIN",
# "subnets": [
# "1.0.0.0/24",
# "1.0.1.0/24"
# ]
# }
# Look up an organization
org = asndb.lookup_org_sync("CLOUD14-ARIN")
# {
# "asns": [
# 13335,
# 14789,
# 395747,
# 394536
# ]
# }
Environment Variables
You can customize the behavior of the ASNDB client by exporting the following environment variables:
BBOT_IO_API_KEY: Your BBOT.IO API key.ASNDB_BASE_URL: The base URL of the ASNDB API (default: https://asndb.api.bbot.io/v1).ASNDB_TIMEOUT: The timeout for the ASNDB API requests (default: 60 seconds).ASNDB_CACHE_SIZE: The size of the cache for the ASNDB API requests (default: 10000).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asndb-1.0.0.tar.gz.
File metadata
- Download URL: asndb-1.0.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23b07e35229939cc972df4a397724756104e9445dcbe0f8d002c49fcc08cccb0
|
|
| MD5 |
f1cad4129f80694be37bba12c44a4e1b
|
|
| BLAKE2b-256 |
66b0b313681a4d90a394e02393de64c90df3c56606974fa705ac4478de7f642f
|
File details
Details for the file asndb-1.0.0-py3-none-any.whl.
File metadata
- Download URL: asndb-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfe4fe6df5bff1b8ade7a02d86054acbce32b16f59952372e37d771955ea4d9c
|
|
| MD5 |
d21651d0d0da7dd013b622fb5667d330
|
|
| BLAKE2b-256 |
64e4ca349f8797171b721a00aabca2ff93c0241bcc111061d7015da62885649d
|