forked from LeoEkky/OpenAI-Codex-Code-Generation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy Grabber.py
More file actions
135 lines (83 loc) · 3.42 KB
/
Copy pathProxy Grabber.py
File metadata and controls
135 lines (83 loc) · 3.42 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
# Proxy Grabber
import urllib.request
import re
import time
import os
import sys
import random
from urllib.error import URLError, HTTPError
class Main:
def __init__(self):
self.dirpath = "proxies"
self.proxy_list = []
self.proxy_list2 = []
if not os.path.exists(self.dirpath):
os.mkdir(self.dirpath)
def main(self):
print("\n\n\t[ Select Proxy Type ]\n")
print(" 1) HTTP/HTTPS")
print(" 2) Socks 4")
print(" 3) Socks 5")
choice = int(input("\nSelect : "))
if choice == 1:
self._http()
print("\nHTTP/HTTPS Proxies have been updated.")
input("Press Enter to Continue...")
sys.exit()
elif choice == 2:
self._socks4()
print("Socks 4 Proxies have been updated.")
input("Press Enter to Continue...")
sys.exit()
elif choice == 3:
self._socks5()
print("Socks 5 Proxies have been updated.")
input("Press Enter to Continue...")
sys.exit()
def _http(self):
print("\n HTTP/HTTPS Proxy Grabber")
print(" =========================\n")
http_url = "https://free-proxy-list.net/"
https_url = "https://www.proxy-list.download/api/v1/get?type=https"
self._get_proxy(http_url, "http")
self._get_proxy(https_url, "https")
def _socks4(self):
print("\n Socks 4 Proxy Grabber")
print(" ======================\n")
url = "https://www.socks-proxy.net/"
data = urllib.request.urlopen(url).read().decode("utf-8")
matches = re.findall(r"<tr><td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td><td>(\d+?)</td>", data)
for match in matches:
ip = match[0]
port = match[1]
self._append_proxy(ip, port, "Socks4", "socks4")
def _socks5(self):
print("\n Socks 5 Proxy Grabber")
print(" ======================\n")
url = "https://www.socks-proxy.net/"
data = urllib.request.urlopen(url).read().decode("utf-8")
matches = re.findall(r"<tr><td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td><td>(\d+?)</td>", data)
for match in matches:
ip = match[0]
port = match[1]
self._append_proxy(ip, port, "Socks5", "socks5")
def _get_proxy(self, url: str, type: str):
data = urllib.request.urlopen(url).read().decode("utf-8")
matches = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+", data)
for match in matches:
ip = match.split(":")[0]
port = match.split(":")[1]
self._append_proxy(ip, port, type)
def _append_proxy(self, ip: str, port: str, type: str, subtype: str="http"):
if not os.path.exists(f"{self.dirpath}/{subtype}.txt"):
open(f"{self.dirpath}/{subtype}.txt", "w").close()
with open(f"{self.dirpath}/{subtype}.txt", "r") as f:
proxylist = f.read()
if ip in proxylist and subtype == "http":
return None
elif ip in proxylist and subtype == "https":
return None
with open(f"{self.dirpath}/{subtype}.txt", "a") as f:
f.write("".join([ip + ":" + port + "\n"]))
if __name__ == "__main__":
Main().main()