Skip to content

mattcarrollcode/pangea

Repository files navigation

Pangea API usage

Setup

Note: this setup has only been testing for macOS.

Python

  1. clone this repo and cd to the root of the repo
  2. Install pyenv and pyenv-virtualenv: brew install pyenv pyenv-virtualenv
  3. Add the following to your ~/.bashrc or ~/.zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Ensure your RC file has been run in your current shell: source ~/.zshrc or source ~/.zshrc
  2. install Python version 3.11.2: pyenv install 3.11.2
  3. Create a new virtual enviornemtn: pyenv virtualenv 3.11.2 pangea
  4. Link the virutal enviornemtn to the repo: pyenv local pangea
  5. Ensure you are using the enviornment you just created:pyenv which python you should see something like: .pyenv/versions/pangea/bin/python. if you don't see pangea somewhere in the path, you've made a mistake somewhere
  6. pip install -r requriements.txt

Pangea

  1. Create a Pangea account: https://pangea.cloud/docs/admin-guide/getting-started/create-account/
  2. Login to Pangea console
  3. Go to the Tokens page: https://console.pangea.cloud/project/tokens and click on the the "Create" button in the upper right hand corner
  4. Enter a name for the token and click the box labeled IP Intel pangea console token creation page then click the Create token button
  5. Next, in the list of tokens, click the copy symbole on the token you just created and paste it in the .env file in the repo in plac eof CHANGE_ME for the value of PANGEA_INTEL_TOKEN

Running the code

  1. Run python pangea-ip-intel-example.py You should see similar output to what is below:
    $ python pangea-ip-intel-example.py
    Calling Pangea IP Intel Geolocate API with IP Address '93.231.182.110'...
    {   'area_codes': '?',
        'city': 'unna',
        'city_code': 7627,
        'city_conf': 95,
        'connection_speed': 'xdsl',
        'connection_type': 'wifi',
        'continent_code': 5,
        'country': 'deu',
        'country_code': 276,
        'country_conf': 99,
        'country_name': 'Federal Republic Of Germany',
        'gmt_offset': 200,
        'in_dst': 'y',
        'internal_code': 24,
        'latitude': 51.56,
        'longitude': 7.65,
        'max_ip': '93.231.182.111',
        'metro_code': 276002,
        'min_ip': '93.231.182.104',
        'postal_code': '59425',
        'postal_conf': 90,
        'region': 'nw',
        'region_code': 10528,
        'region_conf': 99,
        'timezone_name': 'europe/berlin',
        'two_letter_country': 'de'}
    
    

Notes

IP Intel API response

The IP Intel API response has two parts: data and raw_data

  • Data:
    {   'city': 'unna',
        'country': 'Federal Republic Of Germany',
        'country_code': 'de',
        'latitude': 51.56,
        'longitude': 7.65,
        'postal_code': '59425'}
    
  • Raw Data:
    {   'area_codes': '?',
        'city': 'unna',
        'city_code': 7627,
        'city_conf': 95,
        'connection_speed': 'xdsl',
        'connection_type': 'wifi',
        'continent_code': 5,
        'country': 'deu',
        'country_code': 276,
        'country_conf': 99,
        'gmt_offset': 200,
        'in_dst': 'y',
        'internal_code': 24,
        'latitude': 51.56,
        'longitude': 7.65,
        'max_ip': '93.231.182.111',
        'metro_code': 276002,
        'min_ip': '93.231.182.104',
        'postal_code': '59425',
        'postal_conf': 90,
        'region': 'nw',
        'region_code': 10528,
        'region_conf': 99,
        'timezone_name': 'europe/berlin',
        'two_letter_country': 'de'}
    

these two sets of data are idential except that country spells out the name of the country (e.g. Federal Republic Of Germany) in data while country uses the country abreviation in raw_data (e.g. deu). In the future combining these two sets of data into one might be benefical (you country_name could be used for the spelled out name).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages