|
| 1 | +import argparse |
| 2 | +import httpx |
| 3 | +import asyncio |
| 4 | +from tqdm import tqdm |
| 5 | +from colorama import Fore, Style |
| 6 | + |
| 7 | +# Banner |
| 8 | +BANNER = """ |
| 9 | +╔═══════════════════════════════╗ |
| 10 | +║ StatusChecker.py ║ |
| 11 | +║ Created By: BLACK_SCORP10 ║ |
| 12 | +║ Telegram: @BLACK_SCORP10 ║ |
| 13 | +╚═══════════════════════════════╝ |
| 14 | +""" |
| 15 | + |
| 16 | +# Color Codes |
| 17 | +COLORS = { |
| 18 | + "1xx": Fore.WHITE, |
| 19 | + "2xx": Fore.GREEN, |
| 20 | + "3xx": Fore.YELLOW, |
| 21 | + "4xx": Fore.RED, |
| 22 | + "5xx": Fore.LIGHTRED_EX, |
| 23 | + "Invalid": Fore.WHITE |
| 24 | +} |
| 25 | + |
| 26 | +# Function to check URL status |
| 27 | +async def check_url_status(session, url_id, url): |
| 28 | + if "://" not in url: |
| 29 | + url = "https://" + url # Adding https:// if no protocol is specified |
| 30 | + try: |
| 31 | + response = await session.head(url) |
| 32 | + return url_id, url, response.status_code |
| 33 | + except httpx.RequestError: |
| 34 | + return url_id, url, None |
| 35 | + |
| 36 | +# Function to parse arguments |
| 37 | +def parse_arguments(): |
| 38 | + parser = argparse.ArgumentParser(description="URL Status Checker") |
| 39 | + parser.add_argument("-d", "--domain", help="Single domain/URL to check") |
| 40 | + parser.add_argument("-l", "--list", help="File containing list of domains/URLs to check") |
| 41 | + parser.add_argument("-o", "--output", help="File to save the output") |
| 42 | + parser.add_argument("-v", "--version", action="store_true", help="Display version information") |
| 43 | + parser.add_argument("-update", action="store_true", help="Update the tool") |
| 44 | + return parser.parse_args() |
| 45 | + |
| 46 | +# Main function |
| 47 | +async def main(): |
| 48 | + args = parse_arguments() |
| 49 | + |
| 50 | + if args.version: |
| 51 | + print("StatusChecker.py version 1.0") |
| 52 | + return |
| 53 | + |
| 54 | + if args.update: |
| 55 | + print("Checking for updates...") # Implement update logic here |
| 56 | + return |
| 57 | + |
| 58 | + print(BANNER) |
| 59 | + |
| 60 | + urls = set() |
| 61 | + |
| 62 | + if args.domain: |
| 63 | + urls.add(args.domain) |
| 64 | + elif args.list: |
| 65 | + with open(args.list, 'r') as file: |
| 66 | + urls.update(file.read().splitlines()) |
| 67 | + else: |
| 68 | + print("No input provided. Use -d or -l option.") |
| 69 | + return |
| 70 | + |
| 71 | + async with httpx.AsyncClient() as session: |
| 72 | + results = {} |
| 73 | + tasks = [check_url_status(session, url_id, url) for url_id, url in enumerate(urls)] |
| 74 | + if len(urls) > 1: |
| 75 | + with tqdm(total=len(urls), desc="Checking URLs") as pbar: |
| 76 | + for coro in asyncio.as_completed(tasks): |
| 77 | + url_id, url, status_code = await coro |
| 78 | + results[url_id] = (url, status_code) |
| 79 | + pbar.update(1) |
| 80 | + else: |
| 81 | + for coro in asyncio.as_completed(tasks): |
| 82 | + url_id, url, status_code = await coro |
| 83 | + results[url_id] = (url, status_code) |
| 84 | + |
| 85 | + status_codes = { |
| 86 | + "1xx": [], |
| 87 | + "2xx": [], |
| 88 | + "3xx": [], |
| 89 | + "4xx": [], |
| 90 | + "5xx": [], |
| 91 | + "Invalid": [] |
| 92 | + } |
| 93 | + |
| 94 | + for url_id, (url, status) in results.items(): |
| 95 | + if status is not None: |
| 96 | + status_group = str(status)[0] + "xx" |
| 97 | + status_codes[status_group].append((url, status)) |
| 98 | + else: |
| 99 | + status_codes["Invalid"].append((url, "Invalid")) |
| 100 | + |
| 101 | + for code, urls in status_codes.items(): |
| 102 | + if urls: |
| 103 | + print(COLORS.get(code, Fore.WHITE) + f'===== {code.upper()} =====') |
| 104 | + for url, status in urls: |
| 105 | + print(f'[Status : {status}] = {url}') |
| 106 | + print(Style.RESET_ALL) |
| 107 | + |
| 108 | + if args.output: |
| 109 | + with open(args.output, 'w') as file: |
| 110 | + for code, urls in status_codes.items(): |
| 111 | + if urls: |
| 112 | + file.write(f'===== {code.upper()} =====\n') |
| 113 | + for url, status in urls: |
| 114 | + file.write(f'[Status : {status}] = {url}\n') |
| 115 | + |
| 116 | +if __name__ == "__main__": |
| 117 | + asyncio.run(main()) |
0 commit comments