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
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
Hashes for pybgpasn-1.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d034fecd9e6901c468f050aeadfab6a916b89d7a1f4ffb7d883240b7b737e9f0 |
|
MD5 | 64d3432316d5b8e530df9eb6430b66f7 |
|
BLAKE2b-256 | 9efad89d66a32187e01c26d3128a5ebe0d76de4d54d1a26d4533688b104cb02e |