Architecture
Built for offline speed and air-gapped reliability
IPMapper downloads the five public RIR delegated-extended files (APNIC, ARIN, RIPE NCC, LACNIC, AFRINIC), resolves prefix overlaps deterministically, flattens nested CIDRs into disjoint sorted interval arrays, and packs the entire global IPv4 and IPv6 table into a single CRC32-verified 515 KB binary snapshot.
Disjoint sorted intervals
Sweep-line flattening collapses 250k+ CIDRs into contiguous
u32 (IPv4) and u64 (IPv6) arrays.
Lookups run in C-speed binary search while preserving exact
longest-prefix-match semantics.
515 KB bundled snapshot
Every Python wheel and Rust binary embeds an up-to-date
prefixes.bin.gz snapshot. Cold load takes 4.2 ms in
Python (2.0 MB RAM, 2.2M lookups/s) and 3.3 ms in Rust (1.92 MB
RAM, 83M IPv4 / 95M IPv6 lookups/s).
Python and Rust parity
Both ipmapper (Python) and ipmapper-rs
(Rust) read and write the exact same IPMP v1 binary
snapshot, share the same CLI commands, and expose the same HTTP
microservice endpoints.
Zero mandatory external APIs
No API keys, no per-request billing, and no outbound network
traffic at lookup time. Refresh from all five RIRs whenever you
want with ipmapper update.
Installation
Choose Python or Rust
All three install paths include the 515 KB global RIR snapshot so lookups work offline immediately after installation.
| Package | Install command | Offline snapshot | Extras |
|---|---|---|---|
| Python (core) | pip install ipmapper |
Bundled (515 KB) | CLI, Python API, HTTP server, ZIP bundles |
| Python (full) | pip install "ipmapper[full]" |
Bundled (515 KB) | Core + MaxMind MMDB binary export (--mmdb) |
| Rust (ipmapper-rs) | cargo install ipmapper-rs |
Embedded in binary | Native CLI, crate library, multi-threaded HTTP service |
Integration recipes
Use it in your stack
Embed IPMapper directly inside your application, transfer it into an air-gapped network, run it as an internal routing sidecar, or query the live edge API.
# FastAPI middleware: zero-network lookup (~0.45 us/req, 2 MB RAM) from fastapi import FastAPI, Request import ipmapper app = FastAPI() ipmapper.lookup("8.8.8.8") # warm index once at startup (~4 ms) @app.middleware("http") async def attach_geo(request: Request, call_next): client_ip = ( request.headers.get("cf-connecting-ip") or request.headers.get("x-forwarded-for", "").split(",")[0].strip() or request.client.host ) request.state.geo = ipmapper.lookup(client_ip) return await call_next(request)
# 1. On a connected machine: download wheelhouse + optional fresh RIR bundle pip download "ipmapper[full]" -d wheels/ ipmapper update && ipmapper export-bundle rir-snapshot.zip # 2. On the air-gapped host: install and verify with zero internet access pip install --no-index --find-links wheels/ "ipmapper[full]" ipmapper import-bundle rir-snapshot.zip ipmapper lookup 8.8.8.8 --country-name --currency
# Start the built-in internal HTTP microservice (Python or Rust) ipmapper serve --host 127.0.0.1 --port 8080 --workers 16 # or native Rust: ipmapper-rs serve --host 127.0.0.1 --port 8080 # Query single or batch endpoints behind nginx / Envoy curl "http://127.0.0.1:8080/lookup/8.8.8.8" curl -X POST "http://127.0.0.1:8080/batch" \ -H "Content-Type: application/json" \ -d '{"ips":["8.8.8.8","1.1.1.1","2001:4860:4860::8888"]}'
// Native Rust crate with embedded 515 KB RIR snapshot use ipmapper_rs::IpLookup; fn main() { let engine = IpLookup::load_default().expect("load bundled snapshot"); let res = engine.lookup_full("8.8.8.8"); println!("{:?}", res); }
# Hosted Cloudflare Pages Function backing this site curl "https://labs.anaskhan.me/ipmapper/api/lookup?ip=8.8.8.8" curl "https://labs.anaskhan.me/ipmapper/api/me"
Edge API
Hosted endpoints
The live demo endpoints on labs.anaskhan.me run as
Cloudflare Pages Functions on the same origin.
| Endpoint | Description |
|---|---|
GET /ipmapper/api/me |
Returns caller IP, country, currency, RIR, ISP, ASN, and timezone from Cloudflare edge metadata. |
GET /ipmapper/api/lookup?ip=<addr> |
Returns edge-cached RIR delegated lookup JSON for any IPv4 or IPv6 literal address. |
{
"ip": "8.8.8.8",
"country_code": "US",
"country_name": "United States of America",
"currency": "USD",
"rir": "ARIN",
"prefix": "8.8.8.0/24",
"source": "rir-delegated"
}
Resources
Explore further
Inspect dual-stack IPv4/IPv6 connectivity and test custom addresses.
format.html IPv4 & IPv6 Formats →Notation rules, zero compression, dual format, and CIDR prefix tables.
interview-prep.html Networking Q&A →50 searchable questions covering RIRs, CIDR, OSI, TCP/UDP, BGP, and security.
github.com/anxkhn/IPMapper Python Source →v2.0.0 source, tests, fuzzing suite, and RIR pipeline.
github.com/anxkhn/ipmapper-rs Rust Source (ipmapper-rs) →Native Rust drop-in CLI, crate, and HTTP service with full parity.
pypi.org/project/ipmapper PyPI Package →Release history and wheels for Python 3.11+.