-
Notifications
You must be signed in to change notification settings - Fork 31
/
checker.php
241 lines (202 loc) · 6.94 KB
/
checker.php
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
<?php
/*
# Modified and adapted for multi-threading by Samuel Allan <[email protected]>
# You can use this script for any purposes, as long as you leave a line of credit somewhere on your page.
#
# Credits to W. Al Maawali for the original script which was great!
# The guy is a founder of Eagle Eye Digital Solutions,
# And a direct link to his demonstration of how this works can be found on:
# https://www.digi77.com/validating-proxy-via-php/
#
#
*/
//Set max execution time
set_time_limit(100);
//We support two ways of using this script,
//The first way is to directly supply an ip:port and get the results.
//Another way to use this script is to supply a filename (e.g. checker.php?file=somefile.txt)
//To determine whether we are being supplied an ip-port or a filename, we'll take a look at the get params
//Step 1 - Check whether the user specified a timeout
if(!isset($_GET['timeout']))
{
die("You must specify a timeout in seconds in your request (checker.php?...&timeout=20)");
}
//Step 2 - Little extras go here
//Default is 'false' not to confuse the IF-logic later on
$socksOnly = false;
if(isset($_GET['proxy_type']))
{
if($_GET['proxy_type'] == "socks")
{
$socksOnly = true;
$proxy_type = "socks";
}
else
{
$proxy_type = "http(s)";
}
}
else
{
$proxy_type = "http(s)";
}
//Step 3 - Go through a loop to determine what the user wants us to do
if(isset($_GET['file']))
{
//If we can't find the file, complain
if(!file_exists($_GET['file']))
{
die("Could not find file '" . $_GET['file'] . "'");
}
//Convert the file to a list of proxies
$array = file($_GET['file']);
CheckMultiProxy($array, $_GET['timeout'], $proxy_type);
}
else if(isset($_GET['ip']) && isset($_GET['port']))
{
CheckSingleProxy($_GET['ip'], $_GET['port'], $_GET['timeout'], true, $socksOnly, $proxy_type);
}
else
{
die("<h2>Could not find the required GET parameters.</h2><br /><b>To check a proxy use:</b><br /><i>checker.php?ip=...&port=...</i><br /><b>To go through a list of proxies (IP:PORT Format) use:</b><br /><i>checker.php?file=...</i>");
}
function CheckMultiProxy($proxies, $timeout, $proxy_type)
{
$data = array();
foreach($proxies as $proxy)
{
$parts = explode(':', trim($proxy));
$url = strtok(curPageURL(),'?');
$data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;
}
$results = multiRequest($data);
$holder = array();
foreach($results as $result)
{
$holder[] = json_decode($result, true)["result"];
}
$arr = array("results" => $holder);
echo json_encode($arr);
}
function CheckSingleProxy($ip, $port, $timeout, $echoResults=true, $socksOnly=false, $proxy_type="http(s)")
{
$passByIPPort= $ip . ":" . $port;
// You can use virtually any website here, but in case you need to implement other proxy settings (show annonimity level)
// I'll leave you with whatismyipaddress.com, because it shows a lot of info.
$url = "http://whatismyipaddress.com/";
// Get current time to check proxy speed later on
$loadingtime = microtime(true);
$theHeader = curl_init($url);
curl_setopt($theHeader, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($theHeader, CURLOPT_TIMEOUT, $timeout);
curl_setopt($theHeader, CURLOPT_PROXY, $passByIPPort);
//If only socks proxy checking is enabled, use this below.
if($socksOnly)
{
curl_setopt($theHeader, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
//This is not another workaround, it's just to make sure that if the IP uses some god-forgotten CA we can still work with it ;)
//Plus no security is needed, all we are doing is just 'connecting' to check whether it exists!
curl_setopt($theHeader, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($theHeader, CURLOPT_SSL_VERIFYPEER, 0);
//Execute the request
$curlResponse = curl_exec($theHeader);
if ($curlResponse === false)
{
//If we get a 'connection reset' there's a good chance it's a SOCKS proxy
//Just as a safety net though, I'm still aborting if $socksOnly is true (i.e. we were initially checking for a socks-specific proxy)
if(curl_errno($theHeader) == 56 && !$socksOnly)
{
CheckSingleProxy($ip, $port, $timeout, $echoResults, true, "socks");
return;
}
$arr = array(
"result" => array(
"success" => false,
"error" => curl_error($theHeader),
"proxy" => array(
"ip" => $ip,
"port" => $port,
"type" => $proxy_type
)
)
);
}
else
{
$arr = array(
"result" => array(
"success" => true,
"proxy" => array(
"ip" => $ip,
"port" => $port,
"speed" => floor((microtime(true) - $loadingtime)*1000),
"type" => $proxy_type
)
)
);
}
if($echoResults)
{
echo json_encode($arr);
}
return $arr;
}
function multiRequest($data, $options = array())
{
// array of curl handles
$curly = array();
// data to be returned
$result = array();
// multi handle
$mh = curl_multi_init();
// loop through $data and create curl handles
// then add them to the multi-handle
foreach ($data as $id => $d) {
$curly[$id] = curl_init();
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
// post?
if (is_array($d)) {
if (!empty($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POST, 1);
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}
// extra options?
if (!empty($options)) {
curl_setopt_array($curly[$id], $options);
}
curl_multi_add_handle($mh, $curly[$id]);
}
// execute the handles
$running = null;
do {
curl_multi_exec($mh, $running);
} while($running > 0);
// get content and remove handles
foreach($curly as $id => $c) {
$result[$id] = curl_multi_getcontent($c);
curl_multi_remove_handle($mh, $c);
}
// all done
curl_multi_close($mh);
return $result;
}
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" .
$_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>