Skip to content

A utility to quickly map IP addresses to their respective ASN

License

Notifications You must be signed in to change notification settings

devanshbatham/ip2asn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published