-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgetproxy.py
More file actions
executable file
·270 lines (255 loc) · 10.4 KB
/
Copy pathgetproxy.py
File metadata and controls
executable file
·270 lines (255 loc) · 10.4 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
###########################################
__app__ = "GetProxy"
__version__ = "0.5"
__author__ = "MatToufoutu"
###########################################
#TODO: sort proxies by speed
import os
import re
import socket
import sys
import urllib2
# put here your own proxy list urls if they display proxies the "ip:port" style
custom_sites = []
proxyfile = "proxylist.txt"
useragent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.6) Gecko/20091218 Firefox/3.5.6"
timeout = 5
socket.setdefaulttimeout(timeout)
regex_ip = re.compile(r"(?:\d{1,3}\.){3}\d{1,3}")
regex_proxy = re.compile(r"(?:\d{1,3}\.){3}\d{1,3}:\d{1,5}")
class GetProxies:
"""Get/sort/check proxies collected from various websites
"""
def __init__(self):
self.trueIP = self.get_true_ip()
if __name__ == '__main__':
print("[+] True IP address: %s"% self.trueIP)
self.codeenlist = []
self.elitelist = []
self.anonlist = []
self.transplist = []
self.otherlist = []
def write_proxy(self, proxy):
"""write a proxy to a text file"""
with open(proxyfile, 'a') as ofile:
ofile.write(proxy + '\n')
return
def get_true_ip(self):
"""get the machine's true IP address"""
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', useragent)]
return opener.open('http://www.whatismyip.com/automation/n09230945.asp').read()
def check(self, proxy):
"""check if <proxy> is anonymous"""
re_pxtype = re.compile(r'You are using (?:<b>)?<font color="#[a-f0-9]{6}">(?: <b>)?(.+ proxy)(?:</b>)?</font>')
re_ip = re.compile(r'IP detected: <font color="#[a-f0-9]{6}">((\d{1,3}\.){3}\d{1,3})')
handler = urllib2.ProxyHandler({'http':proxy})
opener = urllib2.build_opener(handler)
opener.addheaders = [('User-agent', useragent)]
try:
html = opener.open('http://checker.samair.ru/').read()
result = re_pxtype.search(html)
if result:
pxtype = result.groups()[0]
ip = re_ip.search(html).groups()[0]
if pxtype == 'high-anonymous (elite) proxy':
if ip == self.trueIP:
print(" - %s > TRANSPARENT" % proxy)
self.transplist.append(proxy)
else:
print(" - %s > ELITE" % proxy)
self.write_proxy(proxy)
self.elitelist.append(proxy)
elif pxtype == 'anonymous proxy':
print(" - %s > ANONYMOUS" % proxy)
self.anonlist.append(proxy)
else:
if "CoDeeN" in html:
print(" - %s > CODEEN" % proxy)
self.codeenlist.append(proxy.split(":")[0])
else:
print(" - %s > UNDEFINED" % proxy)
self.otherlist.append(proxy)
opener.close()
except KeyboardInterrupt:
opener.close()
clean_exit()
except:
opener.close()
def get_codeen(self, retried=False):
"""get a list of CoDeeN proxies"""
try:
print(" - Gathering a list of known CoDeeN proxies...")
opener = urllib2.build_opener()
html = opener.open('http://fall.cs.princeton.edu/codeen/tabulator.cgi?table=table_all').read()
proxies = regex_ip.findall(html)
for proxy in proxies:
self.codeenlist.append(proxy)
opener.close()
return self.codeenlist
except (urllib2.URLError, socket.timeout):
if retried:
print(" - Site unavailable: Aborting")
opener.close()
return []
else:
print(" - Site unavailable: Retrying")
opener.close()
self.get_codeen(True)
def getfrom_multi(self):
"""get a list from various websites providing small proxy lists"""
sites = custom_sites
proxylist = []
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', useragent)]
for site in sites:
try:
print(" - Gathering proxy list from %s" % site)
html = opener.open(site).read()
proxylist.extend(regex_proxy.findall(html))
except (urllib2.URLError, socket.timeout):
print(" - Site unavailable: Aborting")
pass
opener.close()
return proxylist
def getfrom_ipadress(self, retried=False):
"""get a proxy list from http://www.ip-adress.com/"""
print(" - Gathering proxy list from http://www.ip-adress.com/proxy_list/")
proxylist = []
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', useragent)]
try:
html = opener.open('http://www.ip-adress.com/proxy_list/').read()
proxylist.extend(regex_proxy.findall(html))
opener.close()
return proxylist
except (urllib2.URLError, socket.timeout):
if retried:
print(" - Site unavailable: Aborting")
opener.close()
return []
else:
print(" - Site unavailable: Retrying")
opener.close()
self.getfrom_ipadress(True)
def getfrom_samair(self, retried=False):
"""get a proxy list from http://samair.ru/"""
print(" - Gathering proxy list from http://www.samair.ru/proxy/")
hackregex1 = re.compile(r'(([a-z])=(\d);)+')
hackregex2 = re.compile(r'((\d{1,3}\.){3}\d{1,3})<script type="text/javascript">document\.write\(":"((\+[a-z])+)\)')
token, maxpages = 1, 20
proxylist = []
try:
while token <= maxpages:
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', useragent)]
if token < 10:
html = opener.open('http://www.samair.ru/proxy/proxy-0%d.htm' % token).read()
else:
html = opener.open('http://www.samair.ru/proxy/proxy-%d.htm' % token).read()
hackdict = dict([x.split("=") for x in hackregex1.search(html).group().split(";")][:-1])
iplist = [(x[0], x[2].split("+")[1:]) for x in hackregex2.findall(html)]
for ip, letters in iplist:
ip += ":"
for letter in letters:
ip += hackdict[letter]
proxylist.append(ip)
token += 1
opener.close()
return proxylist
except (urllib2.URLError, socket.timeout):
if retried:
print(" - Site unavailable: Aborting")
opener.close()
return []
else:
print(" - Site unavailable: Retrying")
opener.close()
self.getfrom_samair(True)
def getfrom_proxylist(self, retried=False):
"""get a proxy list from http://www.proxylist.net"""
print(" - Gathering proxy list from http://www.proxylist.net")
baseurl = "http://www.proxylist.net/list/0/0/3/0/"
token, maxpages = 0, 15
proxylist = []
try:
while token <= maxpages:
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', useragent)]
html = opener.open(baseurl+str(token)).read()
proxylist.extend(regex_proxy.findall(html))
token += 1
opener.close()
return proxylist
except (urllib2.URLError, socket.timeout):
if retried:
print(" - Site unavailable: Aborting")
opener.close()
return []
else:
print(" - Site unavailable: Retrying")
opener.close()
self.getfrom_proxylist(True)
def get_all(self):
"""get a proxy list from all possible websites"""
getfuncs = [self.getfrom_multi, self.getfrom_ipadress,
self.getfrom_samair, self.getfrom_proxylist]
proxylist = []
codeenlist = self.get_codeen()
for get_proxy in getfuncs:
try:
proxylist.extend(get_proxy())
except TypeError:
pass
return proxylist
def clean_exit():
"""display the proxy list path and exit"""
print("\n[+] Aborted by user !")
print(" - List path: %s\n" % os.path.join(os.getcwd(), proxyfile))
sys.exit(0)
import pdb
pdb.set_trace()
if __name__ == "__main__":
try:
if os.name == 'posix':
os.system('clear')
elif os.name == 'nt':
os.system('cls')
print(76*"#")
print("\t\t\t[ GetProxy List Maker v%s ]\n" % __version__)
print(76*"#"+"\n")
collector = GetProxies()
if os.path.exists(os.path.join(os.getcwd(), proxyfile)):
os.remove(proxyfile)
collector.write_proxy("### GetProxy Elite Proxies List ###\n")
print("[+] Downloading proxy lists")
proxylist1 = collector.get_all()
proxylist = []
for proxy in proxylist1:
if (proxy not in proxylist) and (proxy not in collector.codeenlist):
proxylist.append(proxy)
print(" - Total proxies: %d\n[+] Checking proxies" % len(proxylist))
for proxy in proxylist:
collector.check(proxy)
print("[+] FINISHED !")
print(" - Total elite proxies: %d" % len(collector.elitelist))
print(" - List path: %s\n" % os.path.join(os.getcwd(), proxyfile))
sys.exit(0)
except KeyboardInterrupt:
clean_exit()