Giter Club home page Giter Club logo

tg-ip-lookup's Introduction

Lookup an IP address to find out which public cloud it originates from

This repository contains python3 code to find out which public cloud an IP address originates from.

Requirements

  • Python3 (3.11)
  • MaxMind license key (for GeoLite2 ASN database). This database is free subject to license restrictions by MaxMind. Sign up here.
  • see also requirements.txt

Supported Clouds

  • Amazon Web Services (AWS)
  • Google Cloud Platform (GCP)
  • Microsoft Azure
  • Oracle Cloud Infrastructure (OCI)
  • Hetzner
  • DigitalOcean
  • Linode
  • Tencent
  • OVH
  • IBM Cloud
  • Vultr
  • Scaleway
  • Fly.io
  • Starlink (yes ok, not a cloud but it is up in the clouds right?)

How it works

For AWS, GCP, Azure and OCI this looks up the IPs using the publicly published IP ranges by these providers.

For the other providers it uses the MaxMind ASN database to lookup IP information.

Internally this is using the ipaddress module in python to do a search through the various CIDR blocks. In future this could be improved if the need arises.

Install Using Python Pip

  1. pip install tg_ip_lookup
  2. Prepare the database, execute python -c "exec(\"import tg_ip_lookup\ntg_ip_lookup.cloudlookup.loadCloudProviderData.main(\'*MaxMind License Key*\')\")"
  3. Try an IP lookup python -c "exec(\"import tg_ip_lookup\ntg_ip_lookup.main(\'XXX.XXX.XXX.XXX\')\")"

Manual Setup

  1. Clone this repo: git clone https://github.com/Twingate-Labs/tg-ip-lookup, & switch into directory
  2. Install requirements (virtual env recommended), e.g. pip install -r requirements.txt
  3. Prepare the database python cloudlookup/loadCloudProviderData.py *MaxMind License Key*. The database should be updated regularly (e.g. daily)
  4. Try an IP lookup, e.g. python lookup_ip.py XXX.XXX.XXX.XXX

tg-ip-lookup's People

Contributors

chenbishop avatar ekampf avatar emrul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tg-ip-lookup's Issues

hung up on microsoft azure?

[jimb0@fedora ~]$ python -c "exec("import tg_ip_lookup\ntg_ip_lookup.cloudlookup.loadCloudProviderData.main('MaxMind License Key')")"
Processing AWS ranges...
Processing GCP ranges...
Processing Azure ranges...
Traceback (most recent call last):
File "", line 1, in
File "", line 2, in
File "/home/jimb0/.local/lib/python3.11/site-packages/tg_ip_lookup/cloudlookup/loadCloudProviderData.py", line 89, in main
azure_public_info = load_networks(lookup_microsoft_download_url('https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519'),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jimb0/.local/lib/python3.11/site-packages/tg_ip_lookup/cloudlookup/loadCloudProviderData.py", line 63, in lookup_microsoft_download_url
download_url = soup.find('a', {'data-bi-containername': 'download retry'})['href']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
[jimb0@fedora ~]$

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.