Created
April 1, 2022 10:46
-
-
Save puzzlepeaches/bb5ed6d2b8a8046c8258b9c5cb6276e4 to your computer and use it in GitHub Desktop.
Download latest Linux projectdiscovery tools with Python. Comment out line 54 if you want to hold on to the zipfiles following download.
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment