Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import subprocess
- import time
- # Fetch SOCKS5 proxies from Mullvad API
- def get_proxies():
- url = "https://api.mullvad.net/network/v1-beta1/socks-proxies"
- response = requests.get(url)
- if response.status_code != 200:
- print("Error fetching proxy data.")
- return []
- try:
- data = response.json()
- if isinstance(data, list):
- return data
- else:
- print("Unexpected proxy response format.")
- return []
- except ValueError as e:
- print(f"Error parsing JSON response: {e}")
- return []
- # Fetch relay information from Mullvad API
- def get_relays():
- url = "https://api.mullvad.net/www/relays/all/?action=query&titles=Alex&format=json&formatversion=2"
- response = requests.get(url)
- if response.status_code != 200:
- print("Error fetching relay data.")
- return []
- try:
- data = response.json()
- if isinstance(data, list):
- return data
- elif isinstance(data, dict):
- return data.get('query', {}).get('pages', [])
- else:
- print("Unexpected response format.")
- return []
- except ValueError as e:
- print(f"Error parsing JSON response: {e}")
- return []
- # Set up the VPN client using the fetched proxy and relay data
- def setup_vpn(proxy, relay):
- print(f"Connecting to VPN using proxy {proxy['ipv4_address']}:{proxy['port']}...")
- # Example VPN setup with OpenVPN (or you can customize as needed)
- command = [
- "openvpn",
- "--config", "path/to/your/openvpn/config.ovpn",
- "--remote", proxy['ipv4_address'], str(proxy['port']),
- "--tls-client", "--auth-nocache",
- "--dev", "tun"
- ]
- try:
- subprocess.run(command, check=True)
- except subprocess.CalledProcessError as e:
- print(f"Error starting VPN client: {e}")
- # Main function to run the VPN client with proxies and relays
- def run_vpn_client():
- proxies = get_proxies()
- relays = get_relays()
- if not proxies or not relays:
- print("No proxies or relays found.")
- return
- # Randomly choose a proxy (you can customize this logic)
- proxy = proxies[0] # For simplicity, taking the first one
- relay = relays[0] # For simplicity, taking the first relay
- print(f"Using proxy: {proxy['hostname']}, {proxy['ipv4_address']}, Port: {proxy['port']}")
- print(f"Using relay: {relay.get('title', 'Unknown')}")
- # Set up VPN connection
- setup_vpn(proxy, relay)
- # Run the VPN client
- if __name__ == "__main__":
- while True:
- run_vpn_client()
- time.sleep(30) # Wait for 30 seconds before attempting to reconnect or choose a new proxy/relay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement