Skip to main content

A simple Python CLI + library for looking up ASNs by IP or AS number. Uses BBOT.IO API.

Project description

ASNDB

Python Version PyPI - Version License Ruff Tests

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

uv tool install asndb

# or quick run with uvx
uvx asndb

# or using pip
pip install asndb

Usage (CLI)

Note: anonymous queries are limited to 10/minute. If you need more, you can purchase an API key at the BBOT.IO Developer Portal. Export the key as an environment variable:

export BBOT_IO_API_KEY=<your_api_key>

IP Lookup

asndb ip 1.1.1.1

Output:

{
  "ip": "1.1.1.1",
  "asn": 13335,
  "asn_name": "CLOUDFLARENET",
  "org": "Cloudflare, Inc.",
  "org_id": "CLOUD14-ARIN",
  "country": "US",
  "rir": "ARIN",
  "subnets": null
}

To include subnets in the response, use the --include-subnets / -s flag:

asndb ip -s 1.1.1.1

Output:

{
  "ip": "1.1.1.1",
  "asn": 13335,
  "asn_name": "CLOUDFLARENET",
  "org": "Cloudflare, Inc.",
  "org_id": "CLOUD14-ARIN",
  "country": "US",
  "rir": "ARIN",
  "subnets": [
    "1.0.0.0/24",
    "1.1.1.0/24",
    "..."
  ]
}

AS Number Lookup

asndb asn 13335

Organization Lookup

asndb org CLOUD14-ARIN

Output:

{
  "org_id": "CLOUD14-ARIN",
  "org_name": "Cloudflare, Inc.",
  "country": "US",
  "asns": [
    {"asn": 13335, "name": "CLOUDFLARENET"},
    {"asn": 14789, "name": "CLOUDFLARENET"},
    {"asn": 394536, "name": "CLOUDFLARENET-SFO"},
    {"asn": 395747, "name": "CLOUDFLARENET-SFO05"},
    {"asn": 400095, "name": "CLOUDFLARENET"}
  ]
}

Search

asndb search cloudflare

CLI Help

$ 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                                                                          │
│ search  Search for ASNs by name or description                                             │
╰────────────────────────────────────────────────────────────────────────────────────────────╯

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")
# {
#   "ip": "1.1.1.1",
#   "asn": 13335,
#   "asn_name": "CLOUDFLARENET",
#   "org": "Cloudflare, Inc.",
#   "org_id": "CLOUD14-ARIN",
#   "country": "US",
#   "rir": "ARIN",
#   "subnets": null
# }

# Include subnets
asn = asndb.lookup_ip_sync("1.1.1.1", include_subnets=True)
# same as above, but with subnets populated

# Look up an AS number
asn = asndb.lookup_asn_sync(13335)

# Look up an organization
org = asndb.lookup_org_sync("CLOUD14-ARIN")
# {
#   "org_id": "CLOUD14-ARIN",
#   "org_name": "Cloudflare, Inc.",
#   "country": "US",
#   "asns": [
#     {"asn": 13335, "name": "CLOUDFLARENET"},
#     {"asn": 14789, "name": "CLOUDFLARENET"},
#     ...
#   ]
# }

# Search
results = asndb.search_sync("cloudflare")

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asndb-1.0.4.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asndb-1.0.4-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file asndb-1.0.4.tar.gz.

File metadata

  • Download URL: asndb-1.0.4.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for asndb-1.0.4.tar.gz
Algorithm Hash digest
SHA256 23989a4a09e66b76a86b1a36eea78138b4a3001b5f909bb89e110635bb1723f2
MD5 674cac7614b4545044305eaceeb1a6f8
BLAKE2b-256 822b86f8d056d24476aeb0f7e63fb971b870f7018e728d9272a05232157cae30

See more details on using hashes here.

File details

Details for the file asndb-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: asndb-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for asndb-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a62e4f5872e12cbd4b146c7583f7bf2a5239e43ed20a63728295058ee3f1a3db
MD5 2d847c85594aa2eda237ba0935b39fdb
BLAKE2b-256 e1d7a9084a90ea60919f84c39dc2302d802c9047b87373fcc2309898ca4095d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page