-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
124 lines (103 loc) · 5 KB
/
main.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
118
119
120
121
122
123
124
import requests
import colorama
from colorama import Fore, Style, init
import re
import webbrowser
import random
import time
init(convert=True)
def read_links_from_file(file_path):
with open(file_path, 'r') as file:
links = file.read().splitlines()
return links
def check_link(link):
try:
if not link.startswith('http://') and not link.startswith('https://'):
link = 'http://' + link
start_time = time.time()
response = requests.get(link, timeout=3)
latency = int((time.time() - start_time) * 1000) # Calculating latency in milliseconds
if response.status_code == 200:
return f"{Fore.GREEN}Working{Style.RESET_ALL} - {latency}ms"
elif response.status_code == 301 or response.status_code == 302:
return f"{Fore.ORANGE}May contain threat{Style.RESET_ALL}"
else:
return f"{Fore.RED}Not working{Style.RESET_ALL}"
except requests.exceptions.RequestException:
return f"{Fore.RED}Not working{Style.RESET_ALL}"
def strip_color_codes(text):
# Regex pattern to match ANSI escape sequences (color codes)
ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
return ansi_escape.sub('', text)
def save_working_links(links, output_file):
with open(output_file, 'w') as file:
for i, link in enumerate(links, start=1):
status = check_link(link)
# Strip color codes for file output
stripped_status = strip_color_codes(status)
file.write(f"{link}\n")
def process_links(links):
working_links = []
for i, link in enumerate(links, start=1):
status = check_link(link)
number_color = Fore.WHITE
link_color = Fore.LIGHTBLUE_EX
status_color = Fore.GREEN if "Working" in status else (Fore.RED if "Not working" in status else Fore.ORANGE)
latency_color = Fore.LIGHTBLUE_EX
if "Working" in status:
status_split = status.split(" - ")
print(f"{number_color}{i}. {Style.RESET_ALL}{link_color}{link}{Style.RESET_ALL} - {status_color}{status_split[0]}{Style.RESET_ALL} - {latency_color}{status_split[1]}{Style.RESET_ALL}")
working_links.append(link) # Append only if it's a working link
else:
print(f"{number_color}{i}. {Style.RESET_ALL}{link_color}{link}{Style.RESET_ALL} - {status_color}{status}{Style.RESET_ALL}")
return working_links
def open_links_in_browser(links, selected_indices):
index_ranges = []
for index_range in selected_indices.split(','):
if '-' in index_range:
start, end = map(int, index_range.split('-'))
index_ranges.extend(range(start, end + 1))
else:
index_ranges.append(int(index_range))
for index in sorted(set(index_ranges)):
if index <= len(links):
webbrowser.open(links[index - 1])
else:
print(f"Invalid index: {index}")
try:
links = read_links_from_file('url.txt')
colors = [Fore.RED, Fore.GREEN, Fore.BLUE]
greeting = r"""
____ ____ ___ __ __ _____ _
| __ ) | _ \ |_ _|\ \/ / |_ _| ___ ___ | |_ ___ _ __
| _ \ | | | | | | \ / _____ | | / _ \/ __|| __| / _ \| '__|
| |_) || |_| | | | / \ |_____| | | | __/\__ \| |_ | __/| |
|____/ |____/ |___|/_/\_\ |_| \___||___/ \__| \___||_|
"""
colored_greeting = ''.join(random.choice(colors) + char for char in greeting)
print(colored_greeting, end='')
additional_links = input("\nIf you want to scan more links, paste them here. Otherwise, leave it blank: ")
if additional_links:
additional_links = additional_links.split() # Split the additional links string into separate links
links.extend(additional_links)
working_links = process_links(links)
save_working_links(working_links, 'works.txt')
print("\n\nWhat do you want to do?\n\n1. Open all links in browser (Only Working)\n\n2. Only open the links I want\n")
while True:
user_choice = input("Enter your choice (1 or 2): ").strip()
if user_choice in ['1', '2']:
break
else:
print("Invalid choice. Please enter either 1 or 2.")
if user_choice == '1':
for link in working_links:
webbrowser.open(link)
elif user_choice == '2':
selected_indices = input("Select/choose links by giving corresponding number(s): ").strip()
open_links_in_browser(working_links, selected_indices)
colors = [Fore.RED, Fore.GREEN, Fore.BLUE]
author = "This code was developed by Farhad Ahmed\nFor more information visit me at http://github.com/f4rh4d-4hmed"
colored_text = ''.join(random.choice(colors) + char for char in author)
print(colored_text)
except KeyboardInterrupt:
print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nExiting:)")