skillfed

pyasn

Offline IP address to Autonomous System Number lookup module.

pyasn v1.6.2 94.0K downloads/30d#13,347 on PyPI329
Permissive license MIT DORMANT released

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 pyasn

uv

uv add pyasn

poetry

poetry add pyasn

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 3Topic :: Software Development :: Libraries :: Python ModulesTopic :: System :: Networking

Tags

IP to ASN lookupoffline autonomous system numberBGP prefix lookupIP geolocation routinghistorical IP routing dataradix tree IP lookupASN database query
bgp-routingoffline-lookupnetwork-analysis

More Python Modules packages