Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# ASMap Tool3Tool for performing various operations on textual and binary asmap files,4particularly encoding/compressing the raw data to the binary format that can5be used in Bitcoin Core with the `-asmap` option.7Example usage:8```9python3 asmap-tool.py encode /path/to/input.file /path/to/output.file10python3 asmap-tool.py decode /path/to/input.file /path/to/output.file11python3 asmap-tool.py diff /path/to/first.file /path/to/second.file12python3 asmap-tool.py diff_addrs /path/to/first.file /path/to/second.file addrs.file13```14These commands may take a few minutes to run with `python3`,15depending on the amount of data involved and your machine specs.16Consider using `pypy3` for a faster run time.18### Encoding and Decoding20ASmap files are somewhat large in text form, and need to be encoded21to binary before being used with Bitcoin Core.23The `encode` command takes an ASmap and an output file.25The `--fill`/`-f` flag further reduces the size of the output file26by assuming an AS assignment for an unmapped network if an adjacent network is assigned.27This procedure is lossy, in the sense that it loses information28about which ranges were unassigned.29However, if the input ASmap is incomplete,30this procedure will also reassign ranges that should have an AS assignment,31resulting in an ASmap that may diverge from reality significantly.32Finally, another consequence is that the resulting encoded file33will no longer be meaningful for diffs.34Therefore only use `--fill` if35you want to optimise space, you have a reasonably complete ASmap,36and do not intend to diff the file at a later time.38The `decode` command takes an encoded ASmap and an output file.39As with `encode`, the `--fill`/`-f` flag reduces the output file size40by reassigning subnets. Conversely, the `--non-overlapping`/`-n` flag41increases output size by outputting strictly non-overlapping network ranges.43### Comparing ASmaps45AS control of IP networks changes frequently, therefore it can be useful to get46the changes between two ASmaps via the `diff` and `diff_addrs` commands.48`diff` takes two ASmap files, and returns a file detailing the changes49in the state of a network's AS assignment between the first and the second file.50This command may take a few minutes to run, depending on your machine.52The example below shows the three possible output states:53- reassigned to a new AS (`AS26496 # was AS20738`),54- present in the first but not the second (`# 220.157.65.0/24 was AS9723`),55- or present in the second but not the first (`# was unassigned`).57```58217.199.160.0/19 AS26496 # was AS2073859# 220.157.65.0/24 was AS972360216.151.172.0/23 AS400080 # was unassigned612001:470:49::/48 AS20205 # was AS693962# 2001:678:bd0::/48 was AS207631632001:67c:308::/48 AS26496 # was unassigned64```65`diff` accepts a `--ignore-unassigned`/`-i` flag66which ignores networks present in the second but not the first.68`diff_addrs` is intended to provide changes between two ASmaps and69a node's known peers.70The command takes two ASmap files, and a file of IP addresses as output by71the `bitcoin-cli getnodeaddresses` command.72It returns the changes between the two ASmaps for the peer IPs provided in73the `getnodeaddresses` output.74The resulting file is in the same format as the `diff` command shown above.76You can output address data to a file:77```78bitcoin-cli getnodeaddresses 0 > addrs.json79```80and pass in the address file as the third argument:81```82python3 asmap-tool.py diff_addrs path/to/first.file path/to/second.file addrs.json83```
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.