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.
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()
# Sample execution
python3 src/iplocationchanger/__main__.py \
-w reoiotiyotrkc77690543031b421b \
-l TR -o "/usr/local/openvpn" \
-c "/assets/configmap.json" \
-u "ncpuser@namecheap" -p "PaSsWoRd"
- Linux or macOS
openvpn
is installed on the host PCopenvpn
configuration files- (optional)
openvpn
credentials - WhatIsMyIP API Key
- User with
sudo
permissions without password requirements forkillall
andopenvpn
.
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
python3 -m venv ./.venv
source ./.venv/bin/activate
python -m pip install -r requirements/dev.txt
coverage run --rcfile .coveragerc -m unittest discover -t src/ -s src/tests/unit
coverage report -m
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"
}