-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdix.py
More file actions
64 lines (51 loc) · 1.77 KB
/
Copy pathbdix.py
File metadata and controls
64 lines (51 loc) · 1.77 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
import requests
import threading
import subprocess
import time
try:
import colorama
import pyfiglet
except ImportError:
subprocess.check_call(["python", '-m', 'pip', 'install', 'colorama', 'pyfiglet'])
import colorama
import pyfiglet
colorama.init()
ascii_art = pyfiglet.figlet_format("Welcome to BDIX tester")
print(colorama.Fore.GREEN + ascii_art + colorama.Style.RESET_ALL)
def check_link(link, processed, total):
try:
response = requests.get(link, timeout=5)
if response.status_code == 200:
with open('alive.txt', 'a') as f:
f.write(link + '\n')
else:
with open('dead.txt', 'a') as f:
f.write(link + '\n')
except:
with open('dead.txt', 'a') as f:
f.write(link + '\n')
processed.append(link)
print(colorama.Fore.RED + f"{len(processed)}/{total} links processed." + colorama.Style.RESET_ALL)
filename = input('Enter the filename : ')
try:
with open(filename, 'r') as f:
links = f.read().splitlines()
except FileNotFoundError:
print("Please input a valid text file")
exit()
num_threads = int(input('Enter the number of threads to use: '))
total_links = len(links)
processed_links = []
start_time = time.time()
for i in range(0, total_links, num_threads):
threads = []
for j in range(i, min(i+num_threads, total_links)):
link = links[j]
thread = threading.Thread(target=check_link, args=(link, processed_links, total_links))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
end_time = time.time()
print(f'All links processed in {end_time-start_time:.2f} seconds.')
input("Press any key to exit.")