Skip to main content

A small package for obtaining the Registered ISP name per ASN number

Project description

PYBGPASN

pybgpasn is a Python package for looking up Autonomous System Number (ASN) information. The package includes a database of ASNs and their corresponding provider names.

Installation

You can install pybgpasn using pip:

pip install pybgpasn

Usage

Basic Usage

To use pybgpasn, first create an instance of the ASNCatalog class:

from pybgpasn import ASNCatalog

catalog = ASNCatalog()

The ASNCatalog class loads the ASN data from the package database file during initialization.

To look up an ASN's provider name, call the get_provider_name method:

asn = 15169  # Google LLC
provider_name = catalog.get_provider_name(asn)
print(provider_name)  # prints "Google LLC"

Private ASNs

If the provided ASN falls within the range of 64512 to 65535 (inclusive), the get_provider_name method will return "PRIVATE AS":

asn = 64512  # Start of private ASN range
provider_name = catalog.get_provider_name(asn)
print(provider_name)  # prints "PRIVATE AS"

asn = 65535  # End of private ASN range
provider_name = catalog.get_provider_name(asn)
print(provider_name)  # prints "PRIVATE AS"

Errors

If an invalid ASN is provided to the get_provider_name method, an error will be raised.

  • If the provided ASN is not an integer, a TypeError will be raised.
  • If the provided ASN is outside the valid range of 0 to 4294967295, a ValueError will be raised.

Here's an example of handling errors when looking up an ASN:

from pybgpasn import ASNCatalog

catalog = ASNCatalog()

try:
    asn = "invalid"  # Not an integer
    provider_name = catalog.get_provider_name(asn)
except TypeError as e:
    print(f"Error: {e}")
    # Output: Error: ASN must be an integer

try:
    asn = -1  # Negative ASN
    provider_name = catalog.get_provider_name(asn)
except ValueError as e:
    print(f"Error: {e}")
    # Output: Error: Invalid ASN number

License

pybgpasn is licensed under the MIT License. See the LICENSE file for more information.

Acknowledgments

pybgpasn includes data from the Border Gateway Protocol (BGP) Autonomous System (AS) Numbers registry maintained by the Internet Assigned Numbers Authority (IANA).

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

pybgpasn-1.0.13.tar.gz (589.6 kB view details)

Uploaded Source

Built Distribution

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

pybgpasn-1.0.13-py3-none-any.whl (592.6 kB view details)

Uploaded Python 3

File details

Details for the file pybgpasn-1.0.13.tar.gz.

File metadata

  • Download URL: pybgpasn-1.0.13.tar.gz
  • Upload date:
  • Size: 589.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.9

File hashes

Hashes for pybgpasn-1.0.13.tar.gz
Algorithm Hash digest
SHA256 646a676da2117876dd91418fef5217c19842e479b590891657a1408981de8a77
MD5 d0b0f82b0c1b20699a3119a33a49d87e
BLAKE2b-256 17edc9e00ed9a0579421a0623c7926865701d3b674fb2dc656f4e9d6a5585893

See more details on using hashes here.

File details

Details for the file pybgpasn-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: pybgpasn-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 592.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.9

File hashes

Hashes for pybgpasn-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 af0f6a86bfe8110f1a24eb8098bc2a907657434117dfd6ae0977abe538c9b4d7
MD5 5835dca81ed660e3aa77bf87c4d74670
BLAKE2b-256 8127cceb9fb6ebe18e23dbe7ea706dc1466ecb92b02ec7852b26ebbe52fff679

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