Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.9 kB
3
Indexable
Never
import os
import time
import random
import subprocess
import requests
import secrets

# 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[100]
# Shuffle the list of config files to ensure that the same connection is never used twice
random.choice(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
    
# Loop through the config files and rotate the connection
for i in range(len(config_files)):
    # Select a random config file from the list
    current_config = random.choice(config_files)
    print('Switching to ' + current_config)
    
    # 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 60 seconds to give OpenVPN time to start up
    time.sleep(60)
    
    # 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]