PHP proxy check that also checks proxy that also checks it’s anonimity (using curl_multi)
Friday, April 16, 2010 16:04Based on the requests from some others, they wanted a script that not only checked for useful proxies but to see how anonymous they are. The first one you upload to some server, it rates the proxy based on the header information passed. 3 being highly anonymous to 1 being a transparent proxy.
<?php
//proxy levels
//Level 3 Elite Proxy, connection looks like a regular client
//Level 2 Anonymous Proxy, no ip is forworded but target site could still tell it's a proxy
//Level 1 Transparent Proxy, ip is forworded and target site would be able to tell it's a proxy
if(!$_SERVER['HTTP_X_FORWARDED_FOR'] && !$_SERVER['HTTP_VIA'] && !$_SERVER['HTTP_PROXY_CONNECTION']){
echo '3';
} elseif(!$_SERVER['HTTP_X_FORWARDED_FOR']){
echo '2';
} else echo '1';
?>
This next script can be run from anywhere:
<?php
function checkProxies($proxies){
//$proxies is an array of proxies in format ip:port,username:password
$url = 'http://www.someplace.tld/proxycheck.php'; //url to query
$count = count($proxies); //number of items in array
echo 'Number of proxies in list: ' . $count . '<br />';
$curl_arr = array();
$master = curl_multi_init(); //create multi curl resource
for($i = 0; $i < $count; $i++) {
$proxy = $proxies[$i]; //grab proxy from array
$curl_arr[$i] = curl_init(); // create new curl resource
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, TRUE); //return the data don't output it outright
curl_setopt($curl_arr[$i], CURLOPT_HEADER, FALSE); //do not output the header info
curl_setopt($curl_arr[$i], CURLOPT_URL, $url); //set our url to query
curl_setopt($curl_arr[$i], CURLOPT_CONNECTTIMEOUT, 10); //set how long we'll give the proxy to respond in seconds in this instance 10 seconds
$cproxy = explode(',', $proxy); //split the proxy into an array $cproxy[0] will be ip:port $cproxy[1] will be username:password
curl_setopt($curl_arr[$i], CURLOPT_PROXY, $cproxy[0]); //set our proxy ip:port
if($cproxy[1]) { //test for username pass
curl_setopt($curl_arr[$i], CURLOPT_PROXYUSERPWD, $cprosy[1]); //set username:password
}
curl_multi_add_handle($master, $curl_arr[$i]); //add the current curl resource handle to the master
}
$running = null;
do {
curl_multi_exec($master,$running); //while there are running connections just keep looping
} while($running > 0);
echo 'Results: <br />';
$a = 0; //output array counter
for($i = 0; $i < $count; $i++) {
$rawdata = curl_multi_getcontent($curl_arr[$i]); //get returned data from curl handle
if($rawdata == '3'){
//process elite proxy
echo 'Elite Proxy found: ' . $proxies[$i] . '<br /><br />';
$proxylist[$a] = $proxies[$i]; //it's a good proxy add it to our list
$a++;
} elseif($rawdata == '2'){
//process anonymous proxy
echo 'Anonymous Proxy found: ' . $proxies[$i] . '<br /><br />';
$proxylist[$a] = $proxies[$i]; //it's a good proxy add it to our list
$a++;
} elseif($rawdata == '1') {
//process transparent proxy
echo 'Transparnet proxy: ' . $proxies[$i] . ' - Skipping. <br /><br />';
} else echo 'Bad Proxy, nothing returned: ' . $proxies[$i] . ' - Skipping. <br /><br />';
}
echo 'Number of good proxies: ' . count($proxylist);
curl_multi_close($master); //destory the multi curl resource
return $proxylist; //return an array of useable proxies
}
//start of main code
set_time_limit(0);
$proxies = file('proxies.txt'); //loads a file into an array each line being a new element
$proxies = checkProxies($proxies); //$proxies will be a returned array of usable proxies
?>
Enjoy.





















