From e22bc103e5be481a4cb65fe1a2ffed58d7aebd0b Mon Sep 17 00:00:00 2001 From: Kourva <118578799+Kourva@users.noreply.github.com> Date: Fri, 25 Aug 2023 06:48:13 -0400 Subject: [PATCH] Update randomVless.py --- randomVless.py | 72 ++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/randomVless.py b/randomVless.py index 4d9f120..028249c 100644 --- a/randomVless.py +++ b/randomVless.py @@ -1,12 +1,18 @@ #!/usr/bin/env python3 - +# -*- coding: utf-8 -*- # This tool will create random Vless proxies with random servers - # Imports import requests, string, random, time, sys +# Printer +def printer(message: str) -> None: + for char in message: + sys.stdout.write(char) + sys.stdout.flush() + time.sleep(0.01) + print() # Random server name generator def random_name() -> str: @@ -15,37 +21,44 @@ def random_name() -> str: # Gets servers -def get_servers(): +def get_servers() -> zip: names = [] addrs = [] - # Servers from database - with open("ip/all_result.txt") as data: - targets = [url.split("\n")[0] for url in data.readlines()] - for i in range(int(sys.argv[2])): - addrs.append(targets[random.randint(0, len(targets) - 1)]) - names.append(random_name()) + try: + # Get servers from database + with open("ip/all_result.txt") as data: + targets = [ + url.split("\n")[0] for url in data.readlines() + ] + for i in range(int(sys.argv[2])): + addrs.append(targets[random.randint(0, len(targets) - 1)]) + names.append(random_name()) - return zip(names, addrs) - - raise SystemExit("Can't get servers") + return zip(names, addrs) + # Handle exception + except Exception as ex: + raise SystemExit(f"Can't get servers due to '{ex}' (run with -h)!") # Vless generator -def vless_generator(): +def vless_generator() -> list: + + # Open config file with open(sys.argv[1].strip(), "r") as config: - lines = config.read() + lines = config.read().split("\n") - worker = lines.split("\n")[1] - doprax = lines.split("\n")[4] - uuid = lines.split("\n")[7] - path = lines.split("\n")[10] - alias = lines.split("\n")[16] + worker = lines[1] + doprax = lines[4] + uuid = lines[7] + path = lines[10] + alias = lines[16] + # Base vless url vless_url = "vless://{uuid}@{addrs}:443?encryption=none&security=tls&sni={worker_host}&alpn=http%2F1.1&type=ws&host={worker_host}&path={path}#{alias}" - names, addrs = [], [] - result = [] + names, addrs, result = [], [], [] + # Make vless proxies worker_host = worker.split("/")[2] for name, addrs in get_servers(): result.append( @@ -57,22 +70,20 @@ def vless_generator(): alias=alias + "-" + name, ) ) - return result + # Return result + return result # Main function def main(): with open("data/random_result.txt", "a") as result: for proxy in vless_generator(): result.write(proxy + "\n\n") - for char in "\033[2;34m{} Servers saved in data/random_result.txt\033[m\n".format( - int(sys.argv[2]) - ): - print(char, end="", flush=True) - time.sleep(0.01) - + printer( + f"\033[2;34m{int(sys.argv[2])} Servers saved in data/random_result.txt\033[m\n" + ) -# Run the program +# Main if __name__ == "__main__": if len(sys.argv) > 1: if sys.argv[1] in ["-h", "--help"]: @@ -90,6 +101,3 @@ def main(): print("Invalid argument! run with -h") else: print("No argument! run with -h") - - -# EOF