Cloud IP Lookup is a Pure Python application and library for Python 3 to verify which cloud platform a given IP address belongs to (AWS, Azure, OCI, GCP and DigitalOcean).
Reason this release was yanked:
Use v1.0.2
Project description
Cloud IP Lookup v1.0.1
Cloud IP Lookup is a Pure Python application and library for Python 3 to verify which cloud platform a given IP address belongs to. Its supports IPv4 and IPv6, and have its own database that can be updated whenever you want with a simple command: cloudiplookup --update [--verbose]
Data is collected from the websites of the most popular cloud service providers. Sometimes these databases are updated several times a day. We recommend that you put the update command in your crontab, at least once a day.
This version has data from AWS, Azure, Google Cloud, Oracle Cloud and Digital Ocean providers. Some of them provide the names of services and regions, others don´t, like Google Cloud that only provides the network ranges. And it works on Unix, Linux, MacOS and Windows.
We can add other cloud providers, just open an issue at https://github.com/rabuchaim/cloudiplookup/issues. The requirement for addition is that the cloud provider must have a page where its network ranges are published in json, txt or csv format. For example, AWS: https://ip-ranges.amazonaws.com/ip-ranges.json.
What's new in v1.0.1 - 06/Nov/2023
- Changed Digital Ocean URL (just added www to the hostname)
- Collected last modified date from Digital Ocean via http header (previously
last modified date was not collected)
- Print output in csv format (ip,cidr,region,cloud_provider,service,elapsed_time)
- Fixed an issue in the function that adjusts the terminal window. This problem
prevented the cloudiplookup.py script from being executed by crontab.
- Fixed the function that checks the memory used in Windows
- You can run "cloudiplookup" from any path on windows
- Fully tested in Python 3.11, 3.12 and 3.13
- Put some flowers
Installation
pip install cloudiplookup
Or cloning from Github
git clone https://github.com/rabuchaim/cloudiplookup.git
How to use it as a Python library
# python3
Python 3.11.6 (main, Oct 23 2023, 22:48:54) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cloudiplookup import CloudIPLookup
>>> myLookup = CloudIPLookup(verbose=True)
Cloud IP Lookup v1.0.1 is ready! loaded with 48526 networks in 0.00633 seconds and using 4.16 MiB of RAM.
>>> print(myLookup.lookup('52.94.7.24').pp_json())
{
"ip": "52.94.7.24",
"cidr": "52.94.7.0/24",
"region": "sa-east-1",
"cloud_provider": "AWS",
"service": "DYNAMODB",
"elapsed_time": "0.000128607 sec"
}
>>>
>>> result = myLookup.lookup('52.94.7.24')
>>> print(result.cloud_provider)
AWS
>>> print(result.region)
sa-east-1
>>>
>>> result.to_dict()['cloud_provider']
'AWS'
>>> result.to_dict()['region']
'sa-east-1'
>>>
>>> myLookup.get_database_info()
{
"AWS": {
"create_date": "2023-11-04-23-13-07",
"total_networks": 7224
},
"Azure": {
"create_date": "ServiceTags_Public_20231030.json",
"total_networks": 38887
},
"Google Cloud": {
"create_date": "2023-11-05T18:05:11.497316",
"total_networks": 85
},
"Oracle Cloud": {
"create_date": "2023-10-10T04:47:03.138891",
"total_networks": 647
},
"Digital Ocean": {
"create_date": "Thu, 02 Nov 2023 21:29:02 GMT",
"total_networks": 1683
}
}
>>>
>>> from cloudiplookup import update_ip_ranges
>>> update_ip_ranges()
Updating AWS - Downloading IP ranges file [0.185009729 sec]
Updating AWS - Parsing IPv4 and IPv6 ranges [0.010179118 sec]
Updating AZURE - Downloading IP ranges file [15.636473520 sec]
Updating AZURE - Parsing IPv4 and IPv6 ranges [0.087565456 sec]
Updating GCP - Downloading IP ranges file [0.167038122 sec]
Updating GCP - Parsing IPv4 and IPv6 ranges [0.000315775 sec]
Updating ORACLE - Downloading IP ranges file [3.246604505 sec]
Updating ORACLE - Parsing IPv4 and IPv6 ranges [0.000688278 sec]
Updating DIGITAL OCEAN - Downloading IP ranges file [0.263751290 sec]
Updating DIGITAL OCEAN - Parsing IPv4 and IPv6 ranges [0.005341749 sec]
Sorting IPv4 and IPv6 data [0.017409653 sec]
Updating all lists... Done! [0.047161884 sec]
Saved file /var/lib/cloudiplookup/cloudiplookup.dat.gz [0.194174899 sec]
Cloud IP Lookup updated with success! [19.606065781 sec]
>>>
The database file
Cloud IP Lookup uses a pickle database that is a bunch of lists of integers. Everything is located at /var/lib/cloudiplookup/
. On Windows systems, these files are located in the same directory as the library files.
root@tucupi:/var/lib/cloudiplookup# ll
total 184
drwxr-xr-x 2 root root 4096 Nov 6 00:21 ./
drwxr-xr-x 47 root root 4096 Oct 11 21:11 ../
-rw-r--r-- 1 root root 172158 Nov 6 00:15 cloudiplookup.dat.gz
-rw-r--r-- 1 root root 942 Sep 29 10:53 cloudiplookup.json
There is a file /var/lib/cloudiplookup/cloudiplookup.json
with all cloud providers information and an another file /var/lib/cloudiplookup/cloudiplookup.dat.gz
that is the database created by function update_ip_ranges()
.
root@tambaqui:/var/lib/cloudiplookup# cat cloudiplookup.json
{
"AWS": {
"info_page": "https://docs.aws.amazon.com/vpc/latest/userguide/aws-ip-ranges.html",
"download_url": "https://ip-ranges.amazonaws.com/ip-ranges.json"
},
"AZURE": {
"info_page": "https://www.microsoft.com/en-us/download/details.aspx?id=56519",
"download_url": "https://download.microsoft.com/download/(...)/ServiceTags_Public_XXXXXXXX.json"
},
"GCP": {
"info_page": "https://support.google.com/a/answer/10026322?hl=en",
"download_url": "https://www.gstatic.com/ipranges/goog.json"
},
"ORACLE": {
"info_page": "https://docs.oracle.com/pt-br/iaas/Content/General/Concepts/addressranges.htm",
"download_url": "https://docs.oracle.com/iaas/tools/public_ip_ranges.json"
},
"DIGITALOCEAN": {
"info_page": "https://docs.digitalocean.com/products/platform/",
"download_url": "https://digitalocean.com/geo/google.csv"
}
}
Use as a command line application
# ./cloudiplookup.py -h
Sintax: cloudiplookup.py [--csv] [--info] [--update] [--show-config-file] [--verbose] [--debug] [--help] [--version]
[ipaddr,ipaddrN...]
Cloud IP Lookup v1.0.1 - Public cloud services IP addresses lookup tool
Lookup Parameters:
ipaddr,ipaddrN... Supply one or more IP address separated by comma.
Output Options:
--csv, -c Print output in csv format (ip,cidr,region,cloud_provider,service,elapsed_time).
Database Options:
--info, -i Shows information about the current database file.
--update, -u Updates IP ranges directly from cloud service providers. Use -v to see updating progress.
--show-config-file Displays the available settings for downloading information about network ranges.
More Options:
--verbose, -v Shows useful messages about each step that application is doing.
--debug, -d Displays more detailed messages for debugging issues.
--help, -h, -? Shows this help message about the allowed commands.
--version Shows the application version.
# cloudiplookup 3.2.35.65,2600:9000:21e8:2600:1:5a19:8b40:93a1,8.35.192.12,13.71.199.112,5.101.104.55
{
"ip": "3.2.35.65",
"cidr": "3.2.35.64/26",
"region": "sa-east-1",
"cloud_provider": "AWS",
"service": "EC2",
"elapsed_time": "0.000016832 sec"
}
{
"ip": "2600:9000:21e8:2600:1:5a19:8b40:93a1",
"cidr": "2600:9000:2000::/36",
"region": "GLOBAL",
"cloud_provider": "AWS",
"service": "CLOUDFRONT",
"elapsed_time": "0.000024586 sec"
}
{
"ip": "8.35.192.12",
"cidr": "8.35.192.0/20",
"region": "",
"cloud_provider": "Google Cloud",
"service": "",
"elapsed_time": "0.000006054 sec"
}
{
"ip": "13.71.199.112",
"cidr": "13.71.199.112/30",
"region": "westcentralus",
"cloud_provider": "Azure",
"service": "ActionGroup",
"elapsed_time": "0.000004339 sec"
}
{
"ip": "5.101.104.55",
"cidr": "5.101.104.0/22",
"region": "NL-NH Amsterdam",
"cloud_provider": "Digital Ocean",
"service": "",
"elapsed_time": "0.000002593 sec"
}
# ./cloudiplookup.py --csv 3.2.35.65,2600:9000:21e8:2600:1:5a19:8b40:93a1,8.35.192.12,13.71.199.112,5.101.104.55
3.2.35.65,3.2.35.64/26,sa-east-1,AWS,EC2,0.000019659
2600:9000:21e8:2600:1:5a19:8b40:93a1,2600:9000:2000::/36,GLOBAL,AWS,CLOUDFRONT,0.000028556
8.35.192.12,8.35.192.0/20,,Google Cloud,,0.000004661
13.71.199.112,13.71.199.112/30,westcentralus,Azure,ActionGroup,0.000004508
5.101.104.55,5.101.104.0/22,NL-NH Amsterdam,Digital Ocean,,0.000002078
# cloudiplookup --update --verbose
Updating AWS - Downloading IP ranges file [0.224367291 sec]
Updating AWS - Parsing IPv4 and IPv6 ranges [0.008788433 sec]
Updating AZURE - Downloading IP ranges file [12.682546429 sec]
Updating AZURE - Parsing IPv4 and IPv6 ranges [0.077792823 sec]
Updating GCP - Downloading IP ranges file [0.227657207 sec]
Updating GCP - Parsing IPv4 and IPv6 ranges [0.000314343 sec]
Updating ORACLE - Downloading IP ranges file [1.079889933 sec]
Updating ORACLE - Parsing IPv4 and IPv6 ranges [0.000657950 sec]
Updating DIGITAL OCEAN - Downloading IP ranges file [0.825829075 sec]
Updating DIGITAL OCEAN - Parsing IPv4 and IPv6 ranges [0.003529735 sec]
Sorting IPv4 and IPv6 data [0.017580411 sec]
Updating all lists... Done! [0.046246315 sec]
Saved file /var/lib/cloudiplookup/cloudiplookup.dat.gz [0.193161237 sec]
Cloud IP Lookup updated with success! [15.134672344 sec]
Debug mode
If you update the data using the --debug
option, all files downloaded from cloud service providers will be available in the /var/lib/cloudiplookup
directory.
root@tambaqui:/var/lib/cloudiplookup# ll
total 19836
drwxr-xr-x 2 root root 4096 Oct 11 21:12 ./
drwxr-xr-x 47 root root 4096 Oct 11 21:11 ../
-rw-r--r-- 1 root root 10242492 Nov 5 23:27 cloudip.json
-rw-r--r-- 1 root root 172158 Nov 6 00:15 cloudiplookup.dat.gz
-rw-r--r-- 1 root root 4377128 Nov 5 23:27 cloudiplookup.dat.json
-rw-r--r-- 1 root root 942 Sep 29 10:53 cloudiplookup.json
-rw-r--r-- 1 root root 1661309 Nov 5 23:26 ipranges-aws.json
-rw-r--r-- 1 root root 3661377 Nov 5 23:27 ipranges-azure.json
-rw-r--r-- 1 root root 71987 Nov 5 23:27 ipranges-digitalocean.csv
-rw-r--r-- 1 root root 4934 Nov 5 23:27 ipranges-gcp.json
-rw-r--r-- 1 root root 93165 Nov 5 23:27 ipranges-oracle.json
Sugestions, feedbacks, bugs, new cloud service provider requests...
E-mail me: ricardoabuchaim at gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.