Skip to main content

Reliable IP location changer using OpenVPN and WhatIsMyIP

Project description

IP Location Changer

tests

Reliable IP location changer using OpenVPN and WhatIsMyIP.

This package allows changing the IP of the host machine by using openvpn configuration files (and optionally credentials), and verifying the IP location change using WhatIsMyIP.

Usage

from iplocationchanger.service.location_changer_service import LocationChangerService
from iplocationchanger.exception.location_changer_service_exception import LocationChangerServiceException


try:
  lcs = LocationChangerService(
    'reoiotiyotrkc77690543031b421b',
    {
      'TR': '/assets/NCVPN-TR-Istanbul-TCP.ovpn',
    },
    '/usr/local/openvpn',
    '/assets/openvpncredentials',
  )

  country = 'TR'
  try:
    lcs.connect_region(country)
    # Other code logic...

  except LocationChangerServiceException as e:
    # locaiton change failed
    logging.error(e)
    exit(1)
finally:
  lcs.disconnect_region()

Standalone Execution

# Sample execution
python3 src/iplocationchanger/__main__.py \ 
  -w reoiotiyotrkc77690543031b421b \
  -l TR -o "/usr/local/openvpn" \
  -c "/assets/configmap.json" \
  -u "ncpuser@namecheap" -p "PaSsWoRd"

Requirements

  • Linux or macOS
  • openvpn is installed on the host PC
  • openvpn configuration files
  • (optional) openvpn credentials
  • WhatIsMyIP API Key
  • User with sudo permissions without password requirements for killall and openvpn.

Fulfilling sudo requirements without password prompt

Granting sudo requirements to a user without having them supply a password can be approached by editing the /etc/sudoers file as such:

username		ALL = (ALL) NOPASSWD: /usr/bin/killall, /usr/bin/openvpn

Environment Setup

python3 -m venv ./.venv
source ./.venv/bin/activate

python -m pip install -r requirements/dev.txt

Run tests

coverage run --rcfile .coveragerc  -m unittest discover -t src/ -s src/tests/unit

coverage report -m

Config

Config files are JSON-formatted files with 2-letter ISO 3166 country codes as keys and paths to corresponding OpenVPN configuration files as values. A sample config file is shown below:

{
  "TR": "/assets/NCVPN-TR-Istanbul-TCP.ovpn",
  "AR": "/assets/NCVPN-AR-Buenos-Aires-TCP.ovpn"
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iplocationchanger-0.1.0.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

iplocationchanger-0.1.0-py3-none-any.whl (11.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page