From 001ca4114da4b73b44f67de9f98fc29aab04aaa7 Mon Sep 17 00:00:00 2001 From: Kourva <118578799+Kourva@users.noreply.github.com> Date: Fri, 25 Aug 2023 06:47:32 -0400 Subject: [PATCH] Update getVless.py --- getVless.py | 84 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/getVless.py b/getVless.py index 3a03418..d573111 100644 --- a/getVless.py +++ b/getVless.py @@ -1,30 +1,40 @@ #!/usr/bin/env python3 - +# -*- coding: utf-8 -*- # This tool will create Vless proxies with popular servers - # Imports import requests, time, sys +# Printer +def printer(message: str) -> None: + for char in message: + sys.stdout.write(char) + sys.stdout.flush() + time.sleep(0.01) + print() # Gets servers -def get_servers(): - names = [] - addrs = [] +def get_servers() -> zip: + names, addrs = [], [] # Servers from sudoer.net - respones = requests.get("http://bot.sudoer.net/best.cf.iran") - if respones.status_code == 200: - for server in respones.text.split("\n"): - try: - names.append(server.split()[0]) - addrs.append(server.split()[1]) - except: - continue - - # Servers from Isegaro : Thank you so much for your help <3 - # Follow him on Twitter: https://twitter.com/iSegaro + try: + respones = requests.get("http://bot.sudoer.net/best.cf.iran", timeout=5) + if respones.status_code == 200: + for server in respones.text.split("\n"): + try: + names.append(server.split()[0]) + addrs.append(server.split()[1]) + except: + continue + + # Handle exception + except: + printer("\33[2;31mContinue without getting servers from sudoer.net!\33[m") + + finally: + # Servers from Isegaro (https://twitter.com/iSegaro) for addrss, name in [ ("isegaro.ddns.net", "Isegaro1"), ("ip.isegaro.click", "Isegaro2"), @@ -47,25 +57,30 @@ def get_servers(): addrs.append(addrss) names.append(name) + # return results return zip(names, addrs) - raise SystemExit("Can't get servers!") + # Raise SystemExit if any error happened + raise SystemExit("Can't get servers!") # Vless generator -def vless_generator(): +def vless_generator() -> list: + + # Open config file and extract config 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, addrsm, result = [], [], [] + # Make vless url for each server worker_host = worker.split("/")[2] for name, addrs in get_servers(): result.append( @@ -74,23 +89,23 @@ def vless_generator(): addrs=addrs, worker_host=worker_host, path=path, - alias=alias + "-" + name, + alias=f"{alias}-{name}", ) ) - return result + # Return result + return result # Main function def main(): + + # Save urls to file with open("data/result.txt", "a") as result: for proxy in vless_generator(): result.write(proxy + "\n\n") - for char in "\033[2;34mResults saved in data/result.txt\033[m\n": - print(char, end="", flush=True) - time.sleep(0.01) + printer("\033[2;34mResults saved in data/result.txt\033[m\n") - -# Run the program +# Main if __name__ == "__main__": if len(sys.argv) != 1: if sys.argv[1] in ["-h", "--help"]: @@ -108,6 +123,3 @@ def main(): print("Invalid argument! run with -h") else: print("No argument! run with -h") - - -# EOF