Last active
August 11, 2026 04:38
-
-
Save Jacobboogiebear/ebbe859aa4e50fa829da2ffe8ef3c197 to your computer and use it in GitHub Desktop.
Automagically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| certifi==2026.7.22 | |
| charset-normalizer==3.4.9 | |
| distlib==0.4.3 | |
| filelock==3.32.2 | |
| idna==3.18 | |
| packaging==26.3 | |
| pipenv==2026.7.1 | |
| platformdirs==4.11.2 | |
| python-discovery==1.5.1 | |
| requests==2.34.2 | |
| setuptools==84.0.0 | |
| speedtest-cli==2.1.3 | |
| urllib3==2.7.0 | |
| virtualenv==21.7.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This isn't a script, just commands to follow | |
| "wlan0" is my network card found from running "ip addr" | |
| sudo ip netns add vpn_space | |
| sudo ip netns exec vpn_space ip link set dev lo up | |
| sudo ip link add veth_main type veth peer name veth_vpn | |
| sudo ip link set veth_vpn netns vpn_space | |
| sudo ip addr add 10.200.1.1/24 dev veth_main | |
| sudo ip netns exec vpn_space ip addr add 10.200.1.2/24 dev veth_vpn | |
| sudo ip link set veth_main up | |
| sudo ip netns exec vpn_space ip link set veth_vpn up | |
| sudo ip netns exec vpn_space ip route add default via 10.200.1.1 | |
| sudo sysctl -w net.ipv4.ip_forward=1 | |
| sudo iptables -A FORWARD -i veth_main -o wlan0 -j ACCEPT | |
| sudo iptables -A FORWARD -o veth_main -i wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT | |
| sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import requests | |
| import csv | |
| import time | |
| import base64 | |
| import os | |
| import argparse | |
| import random | |
| from pathlib import Path | |
| VPNGATE_API_URL = "http://www.vpngate.net/api/iphone/" | |
| OPENVPN_CONFIG_PATH = "/tmp/vpngate_config.ovpn" | |
| NETNS_NAME = "vpn_space" | |
| COMPARE_DOWNLOAD_ROOT = 5 | |
| COMPARE_UPLOAD_ROOT = 5 | |
| COMPARE_PING_ROOT = 2500 | |
| COMPARE_COUNTRY_ROOT = "" | |
| COMPARE_OUTPUTS_ROOT = 1 | |
| def run_in_netns(cmd, check=False): | |
| full_cmd = ["ip", "netns", "exec", NETNS_NAME] + cmd | |
| result = subprocess.run(full_cmd, capture_output=True, text=True) | |
| if check and result.returncode != 0: | |
| raise Exception(f"Command failed: {' '.join(cmd)}\n{result.stderr}") | |
| return result | |
| def get_vpngate_configs(): | |
| response = requests.get(VPNGATE_API_URL) | |
| if response.status_code != 200: | |
| return [] | |
| csv_data = response.text.splitlines() | |
| reader = csv.DictReader(csv_data[1:]) | |
| servers = [] | |
| for row in reader: | |
| if row.get('OpenVPN_ConfigData_Base64'): | |
| servers.append(row) | |
| return servers | |
| def connect_vpn(config_data): | |
| config_content = base64.b64decode(config_data['OpenVPN_ConfigData_Base64']).decode('utf-8') | |
| with open(OPENVPN_CONFIG_PATH, 'w') as f: | |
| f.write(config_content) | |
| cmd = [ | |
| "openvpn", | |
| "--config", OPENVPN_CONFIG_PATH, | |
| "--dev", "tun", | |
| "--redirect-gateway", "def1", | |
| "--daemon" | |
| ] | |
| result = run_in_netns(cmd) | |
| time.sleep(10) | |
| check_cmd = ["curl", "-s", "--max-time", "5", "ifconfig.me"] | |
| try: | |
| check_result = run_in_netns(check_cmd) | |
| return check_result.stdout.strip() | |
| except: | |
| return 0 | |
| def run_speed_test(): | |
| cmd = ["/home/clair/Projects/vpnauto/.venv/bin/speedtest-cli", "--simple"] | |
| result = run_in_netns(cmd) | |
| lines = result.stdout.strip().split('\n') | |
| download = upload = ping = 0 | |
| for line in lines: | |
| if "Download:" in line: | |
| download = float(line.split()[1]) | |
| elif "Upload:" in line: | |
| upload = float(line.split()[1]) | |
| elif "Ping:" in line: | |
| ping = float(line.split()[1]) | |
| return download, upload, ping | |
| def disconnect_vpn(): | |
| cmd = ["pkill", "-f", "openvpn.*vpngate_config"] | |
| run_in_netns(cmd) | |
| time.sleep(2) | |
| if os.path.exists(OPENVPN_CONFIG_PATH): | |
| os.remove(OPENVPN_CONFIG_PATH) | |
| def check_netns_exists(): | |
| result = subprocess.run(["ip", "netns", "list"], capture_output=True, text=True) | |
| return NETNS_NAME in result.stdout | |
| if __name__ == "__main__": | |
| print("Starting automated VPNGate finder...") | |
| parser = argparse.ArgumentParser(description="Quick VPNGate VPN finder/tester") | |
| parser.add_argument("-d", "--download", type=float, default=COMPARE_DOWNLOAD_ROOT, help="Minimum Download Speed") | |
| parser.add_argument("-u", "--upload", type=float, default=COMPARE_UPLOAD_ROOT, help="Minimum Upload Speed") | |
| parser.add_argument("-p", "--ping", type=float, default=COMPARE_PING_ROOT, help="Maximum Ping") | |
| parser.add_argument("-c", "--country", type=str, default=COMPARE_COUNTRY_ROOT, help="Country of Server") | |
| parser.add_argument("-o", "--outputs", type=int, default=COMPARE_OUTPUTS_ROOT, help="Amount of servers to save") | |
| args = parser.parse_args() | |
| download_limit = args.download | |
| upload_limit = args.upload | |
| ping_limit = args.ping | |
| country_limit = args.country | |
| output_file_target_count = args.outputs | |
| limit_str = "" | |
| if output_file_target_count > COMPARE_OUTPUTS_ROOT: | |
| limit_str = f"Saving {output_file_target_count} vpn profiles\n" | |
| limit_str = f"{limit_str}Current Limits:\n\t" | |
| if country_limit != COMPARE_COUNTRY_ROOT: | |
| limit_str = f"{limit_str}Country: {country_limit}\n\t" | |
| if download_limit != 0: | |
| limit_str = f"{limit_str}Download Speed (Mbps): {download_limit}\n\t" | |
| if upload_limit != 0: | |
| limit_str = f"{limit_str}Upload Speed (Mbps): {upload_limit}\n\t" | |
| if ping_limit != COMPARE_PING_ROOT: | |
| limit_str = f"{limit_str}Ping (MS): {ping_limit}\n" | |
| print(limit_str) | |
| if not check_netns_exists(): | |
| print(f"Error: Namespace {NETNS_NAME} not found") | |
| exit(1) | |
| result_list = [] | |
| passed_list = [] | |
| passed_count = 0 | |
| all_servers = get_vpngate_configs() | |
| random.shuffle(all_servers) | |
| server_index = 0 | |
| for server in all_servers: | |
| server_index_c = server_index | |
| vpn_country = server.get('CountryLong') | |
| vpn_ip = server.get('IP') | |
| vpn_gate_speed = server.get('Speed') | |
| vpn_operator = server.get('Operator') | |
| vpn_current_sessions = server.get('NumVpnSessions') | |
| print(f"[Server {server_index_c}]\n\tIP: {vpn_ip}\n\tCountry: {vpn_country}") | |
| try: | |
| if country_limit != "" and country_limit != vpn_country: | |
| print(f"[Server {server_index_c}]\n\tCountry not within limits ({vpn_country} != {country_limit})") | |
| server_index += 1 | |
| continue | |
| connect_vpn(server) | |
| print(f"[Server {server_index_c}]\n\tConnection Successful") | |
| download_speed, upload_speed, ping = run_speed_test() | |
| ovpn_file = base64.b64decode(server.get('OpenVPN_ConfigData_Base64')).decode('utf-8') | |
| passes = True | |
| if download_speed < download_limit: | |
| passes = False | |
| if upload_speed < upload_limit: | |
| passes = False | |
| if ping == ping_limit: | |
| passes = False | |
| pass_or_fail_str = "" | |
| if passes: | |
| pass_or_fail_str = "Passed" | |
| else: | |
| pass_or_fail_str = "Failed" | |
| print(f"[Server {server_index_c}]\n\tSpeed Test {pass_or_fail_str}\n\tDownload Speed (Mbps): {download_speed}/{download_limit}\n\tUpload Speed (Mbps): {upload_speed}/{upload_limit}\n\tPing (MS): {ping}/{ping_limit}") | |
| output_element = { | |
| "download": download_speed, | |
| "upload": upload_speed, | |
| "ping": ping, | |
| "country": vpn_country, | |
| "ip": vpn_ip, | |
| "profile": str(ovpn_file), | |
| "passes": passes | |
| } | |
| result_list.append(output_element) | |
| if passes: | |
| passed_list.append(output_element) | |
| disconnect_vpn() | |
| except Exception as e: | |
| print(f"[Server {server_index_c}]\n\tServer is offline") | |
| output_element = { | |
| "download": 0, | |
| "upload": 0, | |
| "ping": 0, | |
| "country": vpn_country, | |
| "ip": vpn_ip, | |
| "profile": "", | |
| "passes": False | |
| } | |
| result_list.append(output_element) | |
| server_index += 1 | |
| continue | |
| finally: | |
| if country_limit == "" or country_limit == vpn_country: | |
| disconnect_vpn() | |
| time.sleep(5) | |
| server_index += 1 | |
| if len(passed_list) >= output_file_target_count: | |
| break | |
| vpn_out = Path.cwd() / "vpn_output" | |
| vpn_out.mkdir(exist_ok=True) | |
| for vpn_index, vpn_item in enumerate(passed_list): | |
| vpn_out_file = vpn_out / f"vpnout_{vpn_index}.ovpn" | |
| with open(vpn_out_file, 'w') as of: | |
| of.write(vpn_item["profile"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment