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