pyasn
Offline IP address to Autonomous System Number lookup module.
What it is and what it does
pyasn is a C-and-Python extension module that maps IP addresses to their originating Autonomous System Numbers using offline, precomputed databases. It uses a radix tree data structure to store and query IP prefixes efficiently, supporting both IPv4 and IPv6. Unlike online lookup services (whois, dig, JSON APIs), pyasn trades initial database load time for much faster per-lookup performance, making it suitable for bulk or repeated queries.
The package includes utility scripts to download BGP MRT/RIB archives and convert them into local IPASN database files, enabling historical lookups by date. Initial database loading is the most expensive operation; the documentation recommends caching loaded databases when performing multiple historical lookups. The module has no runtime dependencies and compiles on Linux and Windows, though Windows builds require Microsoft Visual C++.
Use it for:
- Bulk IP geolocation and routing analysis in network security or research without repeated online API calls.
- Historical network routing analysis by loading IPASN databases from different dates to track AS ownership changes.
- Building custom BGP prefix lookup tools by converting your own MRT archives into queryable databases.
- Offline network traffic classification and AS-path analysis in environments without external API access.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pyasn performs fast offline IP address to Autonomous System Number (ASN) lookups using prebuilt databases from BGP archives, supporting both current and historical queries.
Yes, if you need offline IP-to-ASN lookups and can tolerate high installation friction (C compiler required). The package is stable and has no known vulnerabilities, but maintenance is dormant—last release was over a year ago. Install only if bulk or historical lookups justify the upfront compilation cost over simpler online alternatives.
Install
pyasn on PyPI
pip
pip install pyasnuv
uv add pyasnpoetry
poetry add pyasnInstalling pyasn
Before you install
Installation requires a C compiler and build tools (high friction); the package is dormant with the last release over a year ago, though the repository remains active with a recent commit in December 2024.
License in practice
MIT license permits commercial and private use with minimal restrictions; you must include the license notice in distributions.
Quickstart
pip install pyasn
import pyasn
asndb = pyasn.pyasn('ipasn_20140513.dat')
result = asndb.lookup('8.8.8.8')
print(result) # (15169, '8.8.8.0/24')
Requires a C compiler and build tools (build-essential on Ubuntu/Debian, Microsoft Visual C++ on Windows); IPASN database file must be downloaded or built separately using pyasn_util_download.py and pyasn_util_convert.py.
Verify before relying
- Whether the package maintains compatibility with Python versions beyond 3.11 given dormant maintenance status.
- Current state of gzip support for IPASN data files mentioned as 'new in v1.6' and any performance implications.
- Availability and freshness of public IPASN data files for download via the provided utility scripts.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 1,078 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 94,035/month — #13,347 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyasn-1.6.2.tar.gz
Keywords: ip, asn, autonomous, system, bgp, whois, prefix, radix, python, routing, networking
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
py-radixImplements a radix tree data structure for…
permissive · top 15,000 on PyPI
geoip2fastGeoIP2Fast performs fast geolocation lookups…
permissive · top 15,000 on PyPI
pybgpkitPython bindings for BGPKIT tools that parse BGP…
permissive · top 15,000 on PyPI
peeringdbA Python client library for querying and…
permissive · top 15,000 on PyPI
whoisitQuery RDAP (Registration Data Access Protocol)…
unclear · top 15,000 on PyPI
netutilsNetutils provides a collection of utility…
permissive · top 15,000 on PyPI
pybgpkit-parserParses BGP (Border Gateway Protocol) update and…
permissive · top 15,000 on PyPI
ipwhoisRetrieves and parses whois and RDAP data for…
permissive · top 15,000 on PyPI
shodanProvides Python access to Shodan's search…
permissive · top 15,000 on PyPI
mac-vendor-lookupResolves MAC addresses to vendor names using a…
permissive · top 15,000 on PyPI