๐๏ธ Installation
โ๏ธ Usage
๐ Updating RIB Data
๐ How It Works
git clone https://github.com/devanshbatham/ip2asn
cd ip2asn
sudo chmod +x setup.sh
./setup.shNote: The utility comes pre-packed with trie data, so if you don't wish to update the RIB data, it should work well right off the bat.
(~)>> cat input_ips.txt | ip2asn
74.122.191.97 [AS15211]
74.122.191.99 [AS15211]
151.101.65.49 [AS54113]
162.159.136.66 [AS13335]
75.2.48.152 [AS16509]
76.223.91.57 [AS16509]
80.239.194.78 [AS1299]
99.86.20.101 [AS16509]
99.86.20.118 [AS16509]- With
--jsonfor JSON output:
(~)>> cat input_ips.txt | ip2asn --json
{
"AS1299": [
"62.115.144.49",
"62.115.37.34",
"62.115.57.70",
"80.239.194.78"
],
"AS11404": [
"65.50.201.2"
],
"AS11696": [
"69.60.198.202"
]
}If you wish to build the trie yourself or want to update the trie data:
- By default,
trie_data.json.gzis saved in the~/.ip2asn/folder. So, firstly, delete the~/.ip2asnfolder. - Run the
get-rib.shscript. - Build the trie using the
--rib-pathor--rpoption with the updated RIB data.
echo "8.8.8.8" | ip2asn --rib-path /path/to/processed_rib.txtThe ip2asn utility employs a trie data structure to map IP address prefixes to their corresponding Autonomous System Numbers (ASN). Each key in the trie represents an IP address prefix, while the corresponding value denotes the AS number that announces these prefixes. The utility checks this trie to find the longest matching prefix for each IP and retrieves its associated ASN.
