import os import re from ping3 import ping import random from multiprocessing import Pool from colorama import init, Fore, Back, Style import tqdm init() pool_size = 20 _print = print def print(data=''): data = str(data) _print(data + Style.RESET_ALL) def ping_host(host): r = ping(host) r = r if type(r) == float else 0 r *= 100 r = int(r) if r == 0: r = 10000 return (host, r) print(Fore.YELLOW + f"\n Ultimate {Fore.BLUE}Surfshark{Fore.YELLOW} VPN pinger") print(Fore.YELLOW + f" - Pool size: {Fore.GREEN}{pool_size}") print(Fore.YELLOW + f" - by {Fore.RED}cofob{Fore.YELLOW} (c) 2022\n") files_unprocessed = os.listdir() files = [] for i in files_unprocessed: if i.endswith("udp.ovpn") and not i.startswith('ru-'): files.append(i) hosts = [] print(f"Pinging {Fore.RED}all except Russian{Style.RESET_ALL} hosts...") names = [] for name in files: with open(name, 'r') as file: text = file.read() r = re.findall(r'remote ([a-z0-9\-.]+)', text)[0] names.append(r) p = Pool(pool_size) for i in tqdm.tqdm(p.imap_unordered(ping_host, names), total=len(names)): hosts.append(i) p.close() p.terminate() print("\nResults:") for host in hosts: print(Fore.GREEN + f"- {Style.RESET_ALL} {host[0]}: " f"{(Fore.GREEN + str(host[1])) if host[1] != 10000 else (Fore.RED + 'offline' + Fore.GREEN)}") hosts.sort(key=lambda x: x[1]) hosts = hosts[:5] print(f"\n{Fore.YELLOW}Best hosts:") for host in hosts: print(f"{Fore.GREEN}- {Style.RESET_ALL}{host[0]}: {Fore.MAGENTA}{host[1]}") rand = random.choice(hosts) for file in files: if file.find(rand[0]) != -1: filename = file break print(Fore.GREEN + "\nSelected random:") print(f"{Fore.GREEN}- {Fore.YELLOW}{rand[0]}: {rand[1]}") print(f"{Fore.GREEN}- {Fore.YELLOW}{filename}") print(f"\n{Fore.GREEN}Launching VPN...") print(f"{Fore.RED}# {Fore.YELLOW}openvpn {filename}") os.system(f"openvpn {filename}")