import os import glob import zipfile import requests from lastversion import latest tools = ["nuclei", "httpx", "dnsx", "subfinder", "naabu", "shuffledns"] def get_version(tools): for i in tools: version = latest( f"projectdiscovery/{i}", output_format="version", pre_ok=True) print(f"Latest version of {i}: {version}") download(version, i) def download(version, tool): url = f"https://github.com/projectdiscovery/{tool}/releases/download/v{version}/{tool}_{version}_linux_amd64.zip" dest_folder = "out" if not os.path.exists(dest_folder): os.makedirs(dest_folder) filename = url.split("/")[-1].replace(" ", "_") file_path = os.path.join(dest_folder, filename) download_path = os.path.abspath(file_path) if os.path.exists(file_path): print(f"Latest version already downloaded: {tool} v{version}") unzip(download_path) print(f"Downloading: {tool} v{version}") r = requests.get(url, stream=True) if r.ok: with open(file_path, "wb") as f: for chunk in r.iter_content(chunk_size=1024 * 8): if chunk: f.write(chunk) f.flush() os.fsync(f.fileno()) unzip(download_path) else: print("Download failed: {}\n{}".format(r.status_code, r.text)) pass def unzip(download_path): with zipfile.ZipFile(download_path, "r") as zip_ref: zip_ref.extractall("out") mdfiles = glob.glob("out/*.md") zipfiles = glob.glob("out/*.zip") for f in mdfiles: try: os.remove(f) except OSError: pass for f in zipfiles: try: os.remove(f) except OSError: pass get_version(tools)