-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxyChecker.py
160 lines (108 loc) · 4.48 KB
/
proxyChecker.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
155
156
157
158
159
160
import re
import os
import sys
import requests
import time
import threading
from colorama import Fore
from concurrent.futures import ThreadPoolExecutor
print("""
_____ _____ _ _
| __ \ / ____| | | |
| |__) | __ _____ ___ _ | | | |__ ___ ___| | _____ _ __
| ___/ '__/ _ \ \/ / | | | | | | '_ \ / _ \/ __| |/ / _ \ '__|
| | | | | (_) > <| |_| | | |____| | | | __/ (__| < __/ |
|_| |_| \___/_/\_/\__, | \_____|_| |_|\___|\___|_|\_\___|_|
__/ |
|___/
""")
class proxyChecker:
def __init__(self, proxyFile, proxyType, threads):
self.proxyFile = proxyFile
self.proxyType = proxyType
self.threads = threads
self.working = 0
self.dead = 0
self.remain = 0
self.lastRemain = 0
self.proxys = []
self.checkThreads()
self.checkProxyType()
self.loadProxys()
self.run()
def checkThreads(self):
if self.threads.isdigit():
self.threads = int(self.threads)
else:
print(f"{Fore.RED} [Error]{Fore.RESET} Please input a valid Number!".format(self.threads))
exit()
def checkProxyType(self):
if self.proxyType != "socks5" and self.proxyType != "https":
print(f"{Fore.RED} [Error]{Fore.RESET} Please input https or socks5!".format(self.proxyType))
exit()
def loadProxys(self):
if os.path.exists(self.proxyFile) == False:
print(f"{Fore.RED} [Error]{Fore.RESET} No File found in that Path!".format(self.proxyFile))
exit()
with open(self.proxyFile) as file:
for line in file:
#remove new lines
line = line.strip()
#check if the current line is an ip adress + port using a regular expression
if re.match(r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+$", line):
self.proxys.append(line)
else:
print(" [!] Proxy not in right Format!".format(line))
proxysCount = len(self.proxys)
if proxysCount == 0:
print(f"{Fore.RED} [Fail]{Fore.RESET} Is proxies.txt empty?")
exit()
self.remain = proxysCount
print(" [{Fore.GREEN}*{Fore.RESET}] Loaded {0} lines from {1}".format(proxysCount, self.proxyFile ))
def checkProxy(self,proxy):
if self.proxyType == "socks5":
protocol = "socks5://"
elif self.proxyType == "https":
protocol = "https://"
proxyDict = {
"https" : protocol + proxy
}
try:
r = requests.get("https://google.de", proxies=proxyDict, timeout=10)
if r.ok:
self.working += 1
self.saveProxy(proxy)
except Exception:
self.dead += 1
self.remain -= 1
def saveProxy(self, proxy):
with open("working_"+self.proxyType+".txt","a") as file:
file.write(proxy + "\n")
def printStatistics(self):
while True:
if self.lastRemain != self.remain:
if os.name == "nt":
os.system("cls")
elif os.name == "posix":
os.system("clear")
print(" [+] Working: {0}".format(self.working))
print(" [-] Dead: {0}".format(self.dead))
print(" [~] Remaining: {0}".format(self.remain))
self.lastRemain = self.remain
if self.remain == 0:
print(f"{Fore.GREEN} Done! Press Enter to Exit.")
input()
quit()
break
time.sleep(0.05)
def run(self):
x = threading.Thread(target=self.printStatistics, args=())
x.start()
with ThreadPoolExecutor(max_workers=self.threads) as executor:
for proxy in self.proxys:
executor.submit(self.checkProxy, proxy)
proxyFile = input(" Proxy File Path >> ")
proxyType = input(" Proxy Type (https/socks5) >> ")
threads = input(" Threads >> ")
print("")
checker = proxyChecker(proxyFile,proxyType,threads)