-
Notifications
You must be signed in to change notification settings - Fork 0
/
__checker.py
63 lines (54 loc) · 1.69 KB
/
__checker.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
import requests
import json
class ProxyChecker():
def __init__(self) -> None:
self.checkedProxy = []
# Check if proxy is working
def checkProxy(self,ptype,proxyip):
if ptype == "https":
proxy = { "https": "https://"+proxyip }
elif ptype == "http":
proxy = { "https": "https://"+proxyip }
elif ptype == "socks5":
proxy = { "http": "socks5h://"+proxyip, "https": "socks5h://"+proxyip }
elif ptype == "socks4":
proxy = { "http": "socks4://"+proxyip, "https": "socks4://"+proxyip }
Session = requests.Session()
response = Session.get('https://google.com', proxies = proxy, timeout=5)
if response.status_code == 200:
return ptype
else:
return ""
# Validate proxy type
def verifyProxy(self,proxy):
proxy_type = "Invalid"
proxy = proxy.replace(" ","")
proxy = proxy.replace("\n","")
# print("Verifying proxy: {}".format(proxy))
try:
proxy_type = self.checkProxy("socks5",proxy)
except:
try:
proxy_type = self.checkProxy("socks4",proxy)
except:
try:
proxy_type = self.checkProxy("https",proxy)
except:
try:
proxy_type = self.checkProxy("http",proxy)
except:
pass
if proxy_type != "Invalid":
# print("Proxy {} is valid and it's type is {}".format(proxy,proxy_type))
self.checkedProxy.append(proxy)
print(self.checkedProxy)
else:
pass
def checkList(self,file,file2):
with open(file, 'r') as f:
for line in f:
self.verifyProxy(line)
with open(file2, "wb") as f:
f.write(self.checkedProxy)
# checker = ProxyChecker()
# checker.checkList("./proxy/http-removed.txt")