Untitled
unknown
python
2 years ago
1.9 kB
3
Indexable
Never
import os import time import random import subprocess import requests # Define the directory where OpenVPN config files are located config_dir = '/root/ipvanish-openvpn/' # Define the path to the OpenVPN authentication file auth_file = '/root/ipvanish.pass' # Get a list of all OpenVPN config files in the directory config_files = os.listdir(config_dir) config_files = [file for file in config_files if file.endswith('.ovpn')] current_config = config_files[0] # Shuffle the list of config files to ensure that the same connection is never used twice random.shuffle(config_files) # Get the original public IP address of the host original_public_ip = requests.get('https://api.ipify.org').text # Define the OpenVPN command to use openvpn_cmd = 'openvpn' # Define the options to use with the OpenVPN command openvpn_options = ['--config', os.path.join(config_dir, current_config), '--auth-user-pass', auth_file] # Loop through the config files and rotate the connection for config_file in config_files: print('Switching to ' + config_file) # Update the OpenVPN options to use the current config file openvpn_options = ['--config', os.path.join(config_dir, current_config), '--auth-user-pass', auth_file] # Start the OpenVPN connection openvpn_process = subprocess.Popen([openvpn_cmd] + openvpn_options) # Wait for 10 seconds to give OpenVPN time to start up time.sleep(3600) # Send a SIGTERM signal to the OpenVPN process to stop the connection openvpn_process.terminate() # Wait for 10 seconds to give OpenVPN time to close the connection time.sleep(10) # Clear the current config file from the OpenVPN options openvpn_options = openvpn_options[:-2] # Get the new public IP address of the host new_public_ip = requests.get('https://api.ipify.org').text