🇺🇸 English | 🇷🇺 Русский
Lightweight self-hosted ASN prefix cache and aggregation service.
Supported data sources:
- RIPEstat
- RouteViews
- RADB
Designed for use with Bird4Static, BIRD Internet Routing Daemon, and other route automation systems.
-
ASN → Prefix caching
-
Multiple data sources:
- RIPEstat
- RouteViews
- RADB
-
Automatic aggregation of results from all available sources
-
RIPEstat-compatible API
-
Local SQLite storage
-
Docker deployment support
-
Low resource consumption
-
Supports thousands of ASN records
-
Can serve multiple routers from a single central instance
Routers
|
v
ASN Cache API
|
+-- SQLite
|
+-- RIPEstat
+-- RouteViews
+-- RADB
Routers communicate only with the ASN Cache API.
The service automatically retrieves data from external sources and stores it locally.
GET /data/announced-prefixes/data.json?resource=AS15169Example response:
{
"status": "ok",
"data": {
"resource": "AS15169",
"prefixes": [
{
"prefix": "8.8.8.0/24"
},
{
"prefix": "8.34.208.0/20"
}
]
}
}GET /healthResponse:
{
"status": "ok"
}Bird4Static normally queries RIPEstat directly:
curl https://stat.ripe.net/data/announced-prefixes/data.json?resource=AS15169After deploying ASN Cache, simply replace the base URL:
curl https://asn-cache.example.com/data/announced-prefixes/data.json?resource=AS15169No additional changes are required in the existing scripts.
Build:
docker compose buildStart:
docker compose up -dVerify:
curl http://127.0.0.1:8080/health- Docker Engine
- Docker Compose Plugin
- Python 3.11+
- FastAPI
- Uvicorn
- SQLite
It is recommended to restrict API access by IP address using a firewall or reverse proxy.
Example iptables configuration:
iptables -A INPUT -p tcp -s <ROUTER_IP_1> --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -s <ROUTER_IP_2> --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j DROPTypical database sizes:
| ASN Count | Database Size |
|---|---|
| 500 | < 5 MB |
| 2,000 | 10–20 MB |
| 10,000 | 50–100 MB |
The service is suitable for low-resource VPS instances.
- Deploy ASN Cache on a central VPS.
- Multiple routers use it as an ASN → Prefix source.
- The service reduces load on RIPEstat and other public services.
- Cached data remains available even if one of the upstream providers becomes temporarily unavailable.
This project was originally designed to work with Bird4Static.
Reference implementation:
See the examples below for integrating ASN Cache as a custom ASN prefix source.
#GET PREFIXES FROM PERSONAL FUNCTION
get_prefixes_personal_func() {
local cur_as="$1"
local result
result="$(
retry_cmd_func "personal" "$cur_as" \
curl -fsSk "http://YOUR_DOMAIN_OR_IP/data/announced-prefixes/data.json?resource=$cur_as" |
jq -r '.data.prefixes[]? | select(.prefix? and (.prefix | contains("."))) | .prefix'
)"
log_source_result_func "personal" "$cur_as" "$result"
printf '%s\n' "$result"
}Locate the following section:
result="$(get_prefixes_ripe_func "$cur_as")"
[[ -z "$result" ]] && result="$(get_prefixes_routeviews_func "$cur_as")"
[[ -z "$result" ]] && result="$(get_prefixes_radb_func "$cur_as")"Replace it with:
result="$(get_prefixes_personal_func "$cur_as")"
[[ -z "$result" ]] && result="$(get_prefixes_ripe_func "$cur_as")"
[[ -z "$result" ]] && result="$(get_prefixes_routeviews_func "$cur_as")"
[[ -z "$result" ]] && result="$(get_prefixes_radb_func "$cur_as")"With this change, Bird4Static will first query ASN Cache. If the service is unavailable or returns no data, the script will automatically fall back to RIPEstat, RouteViews, and RADB.
| Document | Description |
|---|---|
| Nginx Reverse Proxy Configuration | Publishing ASN Cache via HTTP/HTTPS |
If ASN Cache is published through Nginx with TLS enabled:
curl -fsSk "https://asn-cache.example.com/data/announced-prefixes/data.json?resource=$cur_as"Planned features:
- Background ASN refresh scheduler
- IPv6 support
- Source attribution for prefixes
- Metrics and statistics endpoint
- Web-based ASN explorer
- PostgreSQL backend support
- Prefix change history
MIT License