/ip2cloud

Check IP addresses against known cloud provider IP address ranges

Primary LanguagePythonMIT LicenseMIT

ip2cloud

Check IP addresses against known cloud provider IP address ranges

🔧 Installation ⚙️ Usage ⚡ Add New IP Ranges

ip2cloud

Prerequisites

  • Python 3.x
  • intervaltree library (pip install intervaltree)
  • tqdm library (pip install tqdm)

Installation

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

Now, you can use ip2cloud from the command line to check IP addresses against known cloud provider IP address ranges.

Usage

cat input_ips.txt | ip2cloud

The script will process the provided IP addresses and display the corresponding cloud provider for each IP address. Optionally, you can use the -j or --json flag to print the output in JSON format.

Example

Suppose you have a file named input_ips.txt with the following IP addresses:

59.82.33.201
63.32.40.140   
63.33.205.240
64.4.8.90 
64.4.8.67

Run the script as follows:

(~)>> cat input_ips.txt | ip2cloud

[aliyun] : 59.82.33.201
[aws] : 63.32.40.140                         
[aws] : 63.33.205.240        
[azure] : 64.4.8.67 
[azure] : 64.4.8.90   
  • with --json or -j flag:
(~)>> cat input_ips.txt | ip2cloud -j

{
  "aliyun": [
    "59.82.33.201"
  ],
  "aws": [
    "63.32.40.140",
    "63.33.205.240"
  ],
  "azure": [
    "64.4.8.90",
    "64.4.8.67"
  ]
}

If no cloud provider is found for an IP address, it won't appear in the JSON or standard output.

Add New IP Ranges

If you want to add new IP ranges for cloud providers, follow these steps:

  1. Create a new text file in the data folder (e.g., somecloud.txt).
  2. Add the IP address ranges in CIDR notation to the new text file. Each range should be on a separate line.
  3. Run the parse_data script:
python3 parse_data.py

The new IP ranges will be updated in the cloud_data.json file, and ip2cloud will use the updated data for IP lookups.

Note

  • The script only supports IPv4 addresses.
  • Make sure to keep the cloud_data.json file updated with the latest IP address ranges for the cloud providers you want to check.
  • cloud_data.json should be stored in ~/.config/.cloud-ranges folder after running setup.sh

Supported Cloud Providers

The data folder contains IP address ranges for the following mentioned cloud providers, and you are welcome to add IP address ranges for any number of additional providers.

  • Alibaba Cloud (Aliyun)
  • Amazon Web Services (AWS)
  • Microsoft Azure
  • Cloudflare
  • DigitalOcean
  • Fastly
  • Google Cloud
  • IBM Cloud
  • Linode
  • Oracle Cloud
  • Tencent Cloud
  • UCloud