-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
225 lines (188 loc) · 9.88 KB
/
Copy pathmain.py
File metadata and controls
225 lines (188 loc) · 9.88 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import requests
import colorama
from colorama import Fore, Style, init
import re
import webbrowser
import random
import time
import os
import sys
import warnings
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime
init(convert=True)
try:
from urllib3.exceptions import InsecureRequestWarning
warnings.filterwarnings('ignore', category=InsecureRequestWarning)
except ImportError:
pass
def resource_path(relative_path):
if getattr(sys, 'frozen', False):
return os.path.join(os.path.dirname(sys.executable), relative_path)
return os.path.join(os.path.abspath("."), relative_path)
def read_links_from_file(file_path):
with open(file_path, 'r') as file:
links = [line.strip() for line in file if line.strip()]
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=4) #increased timeout to catch more links
latency = int((time.time() - start_time) * 1000)
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.YELLOW}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):
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 link in links:
file.write(f"{link}\n")
def export_working_sites(working_links, failed_links, elapsed_time, total_urls):
"""Export working URLs to timestamped text file"""
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
export_filename = f"bdix_working_sites_{timestamp}.txt"
try:
with open(export_filename, 'w', encoding='utf-8') as f:
f.write("="*80 + "\n")
f.write("BDIX TESTER - WORKING SITES\n")
f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write("="*80 + "\n\n")
success_rate = (len(working_links) / total_urls * 100) if total_urls > 0 else 0
f.write("TESTING SUMMARY:\n")
f.write("-" * 40 + "\n")
f.write(f"Total URLs tested: {total_urls:,}\n")
f.write(f"Working URLs found: {len(working_links):,}\n")
f.write(f"Failed URLs: {len(failed_links):,}\n")
f.write(f"Success rate: {success_rate:.1f}%\n")
f.write(f"Total scan time: {elapsed_time:.1f} seconds\n")
f.write(f"Average time per URL: {(elapsed_time/total_urls):.3f} seconds\n")
f.write(f"Concurrent workers: 50\n\n")
if working_links:
f.write(f"WORKING BDIX SITES ({len(working_links)} sites found):\n")
f.write("=" * 60 + "\n")
for i, url in enumerate(working_links, 1):
f.write(f"{i:3d}. {url}\n")
f.write("\n")
# Additional note
f.write("NOTE:\n")
f.write("-" * 40 + "\n")
f.write("These URLs were confirmed working at the time of testing.\n")
f.write("Network conditions may affect accessibility.\n")
f.write("Some sites may require specific network configurations.\n\n")
else:
f.write("NO WORKING SITES FOUND\n")
f.write("=" * 40 + "\n")
f.write("No working BDIX sites were found during this scan.\n")
f.write("This could be due to network connectivity issues\n")
f.write("or temporary unavailability of services.\n\n")
f.write("="*80 + "\n")
f.write("Generated by BDIX-TESTER\n")
f.write("GitHub: https://github.com/f4rh4d-4hmed/BDIX-TESTER\n")
f.write("Export contains only working sites for easy reference\n")
f.write("="*80 + "\n")
return export_filename
except Exception as e:
print(f"{Fore.RED}Error creating export file: {e}{Style.RESET_ALL}")
return None
def process_links(links):
working_links = []
failed_links = []
results = {}
max_workers = min(50, len(links))
with ThreadPoolExecutor(max_workers=max_workers) as executor:
future_to_url = {executor.submit(check_link, link): (i+1, link)
for i, link in enumerate(links)}
for future in as_completed(future_to_url):
index, link = future_to_url[future]
try:
status = future.result()
results[index] = (link, status)
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.YELLOW)
latency_color = Fore.LIGHTBLUE_EX
if "Working" in status:
status_split = status.split(" - ")
print(f"{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)
else:
print(f"{link_color}{link}{Style.RESET_ALL} - {status_color}{status}{Style.RESET_ALL}")
failed_links.append(link)
except Exception as e:
print(f"{number_color}{index}. {Style.RESET_ALL}{link_color}{link}{Style.RESET_ALL} - {Fore.RED}Error{Style.RESET_ALL}")
failed_links.append(link)
return working_links, failed_links, results
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 1 <= index <= len(links):
webbrowser.open(links[index - 1])
else:
print(f"Invalid index: {index}")
try:
links = read_links_from_file(resource_path('urlv2.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()
links.extend(additional_links)
start_time = time.time()
working_links, failed_links, all_results = process_links(links)
end_time = time.time()
###########################Removed because of update##################
#########save_working_links(working_links, resource_path('works.txt'))
######################################################################
elapsed = end_time - start_time
success_rate = (len(working_links) / len(links)) * 100 if links else 0
failed_count = len(failed_links)
avg_time_per_url = elapsed / len(links) if links else 0
print(f"\n{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
print(f"{Fore.CYAN}TESTING SUMMARY{Style.RESET_ALL}")
print(f"{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
print(f"Total URLs tested: {Fore.WHITE}{len(links):,}{Style.RESET_ALL}")
print(f"Working URLs: {Fore.GREEN}{len(working_links):,}{Style.RESET_ALL}")
print(f"Failed URLs: {Fore.RED}{failed_count:,}{Style.RESET_ALL}")
print(f"Success rate: {Fore.YELLOW}{success_rate:.1f}%{Style.RESET_ALL}")
print(f"Total time: {Fore.MAGENTA}{elapsed:.1f} seconds{Style.RESET_ALL}")
print(f"Average time per URL: {Fore.MAGENTA}{avg_time_per_url:.3f} seconds{Style.RESET_ALL}")
print(f"Concurrent workers: {Fore.CYAN}50{Style.RESET_ALL}")
print(f"{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
export_choice = input(f"\n{Fore.YELLOW}Do you want to export working sites to a text file? (y/n): {Style.RESET_ALL}").strip().lower()
if export_choice in ['y', 'yes']:
export_filename = export_working_sites(working_links, failed_links, elapsed, len(links))
if export_filename:
print(f"{Fore.GREEN}✓ Results exported to: {export_filename}{Style.RESET_ALL}")
colors = [Fore.RED, Fore.GREEN, Fore.BLUE]
author = "\n\nMade with love by f4rh4d-4hmed\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:)")
except FileNotFoundError:
print(f"Error: Could not find 'url.txt' file. Please make sure it exists in the same directory as the script.")
except Exception as e:
print(f"An error occurred: {e}")