devanshbatham / ip2asn

A utility to quickly map IP addresses to their respective ASN

Repository from Github https://github.comdevanshbatham/ip2asnRepository from Github https://github.comdevanshbatham/ip2asn

ip2asn

A utility to quickly map IP addresses to their respective ASN

๐Ÿ—๏ธ Installation     โ›๏ธ Usage     ๐Ÿ”„ Updating RIB Data     ๐Ÿ“– How It Works

ip2asn

Installation

git clone https://github.com/devanshbatham/ip2asn
cd ip2asn
sudo chmod +x setup.sh
./setup.sh

Note: 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.

Usage

(~)>> 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 --json for 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"
  ]
}

Updating RIB Data

If you wish to build the trie yourself or want to update the trie data:

  1. By default, trie_data.json.gz is saved in the ~/.ip2asn/ folder. So, firstly, delete the ~/.ip2asn folder.
  2. Run the get-rib.sh script.
  3. Build the trie using the --rib-path or --rp option with the updated RIB data.
echo "8.8.8.8" | ip2asn --rib-path /path/to/processed_rib.txt

How It Works

The 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.

About

A utility to quickly map IP addresses to their respective ASN

License:MIT License


Languages

Language:Python 67.3%Language:Shell 32.7%