asmap 0.1.0

IP to ASN lookup using Bitcoin Core's asmap binary trie format
Documentation
  • Coverage
  • 72.73%
    8 out of 11 items documented1 out of 8 items with examples
  • Size
  • Source code size: 23.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 392.43 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 27s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • 0xB10C/asmap
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 0xB10C

ASmap Interpreter in Rust

A Rust library for IP to ASN (Autonomous System Number) lookups using Bitcoin Core's asmap binary trie format.

What is an ASmap?

An asmap file is a compact binary encoding of a mapping from IP prefixes to ASNs. The format was designed for Bitcoin Core to enable AS-aware peer selection, improving resistance to eclipse attacks by diversifying connections across different autonomous systems.

The binary format uses a trie structure encoded as bytecode instructions, allowing efficient lookups without loading a full routing table into memory.

Usage

use asmap::Asmap;
use std::net::IpAddr;

// Load from file (validates on construction)
let map = Asmap::from_file("path/to/asmap.dat")?;

// Look up any IP address
let asn = map.lookup("8.8.8.8".parse::<IpAddr>().unwrap());
println!("ASN: {asn}"); // 0 means unmapped

// Convenience methods for typed addresses
use std::net::Ipv4Addr;
let asn = map.lookup_v4(Ipv4Addr::new(1, 1, 1, 1));

IPv4 addresses are automatically mapped to IPv6 (::ffff:x.x.x.x) before lookup, matching how Bitcoin Core handles them internally.

Obtaining asmap files

ASmap files are available from bitcoin-core/asmap-data.