Registry / devops / pyasn
library1.6.2pypypi✓ verified 86d ago

pyasn is a Python module for offline IP address to Autonomous System Number (ASN) lookups. It uses a compact IP prefix trie and runs entirely offline once the data files are downloaded. Version 1.6.2 is current; releases are infrequent (last major update 2019).

pip install pyasn
INSTALL
IMPORT
SIG · PYASN
P
pyasn
devopspythonv1.6.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pyasn
import pyasn

Initialize with a downloaded IP-to-ASN database file and perform lookups.

import pyasn asndb = pyasn.pyasn('ipasn.dat') asn, prefix = asndb.lookup('8.8.8.8') print(f'ASN: {asn}, Prefix: {prefix}')
Debug
Known issues
gotchaThe database file (e.g., 'ipasn.dat') must be downloaded separately; it is not included with the package. Use the provided 'pyasn_util_download.py' script or manually fetch from sources like RouteViews.
fix
Run 'pyasn_util_download.py --latest' to download the database, or point pyasn to a custom file.
affects: all
deprecatedThe 'pyasn.pyasn' class is the only supported interface. The older 'PyASN' class (capital P) was removed in version 1.6; using it causes AttributeError.
fix
Use 'import pyasn' and instantiate 'pyasn.pyasn()' instead of 'PyASN()'.
affects: >=1.6
Errors
Common errors & fixes
AttributeError: module 'pyasn' has no attribute 'pyasn'
Attempting to access 'pyasn.pyasn' before importing correctly or using a very old version of the library.
fix
Ensure you have version >=1.0.0 and use 'import pyasn; asndb = pyasn.pyasn()'.
FileNotFoundError: [Errno 2] No such file or directory: 'ipasn.dat'
The database file was not downloaded or the path is incorrect.
fix
Download the database using 'pyasn_util_download.py --latest' or provide the correct path to an existing file.
Upgrade
Version history
1.6.2latest on PyPI · released Sep 1, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pyasn — pip install pyasn · libregistry