-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproxy_check.py
154 lines (114 loc) · 3.93 KB
/
proxy_check.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
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
import concurrent.futures.thread
import os
import shutil
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
from fake_headers import Headers
os.system("")
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
print(bcolors.OKGREEN + """
____
| _ \ _ __ _____ ___ _
| |_) | '__/ _ \ \/ / | | |
| __/| | | (_) > <| |_| |
|_| |_|_ \___/_/\_\\__, |_
/ ___| |__ ___|___/| | _____ _ __
| | | '_ \ / _ \/ __| |/ / _ \ '__|
| |___| | | | __/ (__| < __/ |
\____|_| |_|\___|\___|_|\_\___|_|
""" + bcolors.ENDC)
print(bcolors.OKCYAN + """
[ GitHub : https://github.com/MShawon/YouTube-Viewer ]
""" + bcolors.ENDC)
'''
Backup previous checked goodproxies
'''
try:
os.remove('ProxyBackup.txt')
except:
pass
try:
shutil.copy('good.txt', 'ProxyBackup.txt')
print(bcolors.WARNING + 'Good Proxy backed up in ProxyBackup' + bcolors.ENDC)
os.remove('good.txt')
except:
pass
checked = {}
def load_proxy():
proxies = []
filename = input(bcolors.OKBLUE +
'Enter your proxy file name: ' + bcolors.ENDC)
load = open(filename)
loaded = [items.rstrip().strip() for items in load]
load.close()
for lines in loaded:
if lines.count(':') == 3:
split = lines.split(':')
lines = f'{split[2]}:{split[-1]}@{split[0]}:{split[1]}'
proxies.append(lines)
return proxies
def mainChecker(proxy_type, proxy, position):
checked[position] = None
proxyDict = {
"http": f"{proxy_type}://{proxy}",
"https": f"{proxy_type}://{proxy}",
}
try:
header = Headers(
headers=False
).generate()
agent = header['User-Agent']
headers = {
'User-Agent': f'{agent}',
}
response = requests.get(
'https://www.youtube.com/', headers=headers, proxies=proxyDict, timeout=30)
status = response.status_code
if status != 200:
raise Exception
print(bcolors.OKBLUE + f"Tried {position+1} |" + bcolors.OKGREEN +
f' {proxy} | GOOD | Type : {proxy_type} | Response : {status}' + bcolors.ENDC)
print(proxy, file=open('good.txt', 'a'))
except:
print(bcolors.OKBLUE + f"Tried {position+1} |" + bcolors.FAIL +
f' {proxy} | {proxy_type} |BAD ' + bcolors.ENDC)
checked[position] = proxy_type
pass
def proxyCheck(position):
proxy = proxy_list[position]
mainChecker('http', proxy, position)
if checked[position] == 'http':
mainChecker('socks4', proxy, position)
if checked[position] == 'socks4':
mainChecker('socks5', proxy, position)
def main():
pool_number = [i for i in range(total_proxies)]
with ThreadPoolExecutor(max_workers=threads) as executor:
futures = [executor.submit(proxyCheck, position)
for position in pool_number]
try:
for future in as_completed(futures):
future.result()
except KeyboardInterrupt:
executor._threads.clear()
concurrent.futures.thread._threads_queues.clear()
except IndexError:
print(bcolors.WARNING + 'Number of proxies are less than threads. Provide more proxies or less threads.' + bcolors.ENDC)
pass
if __name__ == '__main__':
threads = 100
proxy_list = load_proxy()
proxy_list = list(set(proxy_list)) # removing duplicate proxies
proxy_list = list(filter(None, proxy_list)) # removing empty proxies
total_proxies = len(proxy_list)
print(bcolors.OKCYAN + f'Total proxies : {total_proxies}' + bcolors.ENDC)
main()