PHP proxy checker using curl_multi
Thursday, April 15, 2010 15:31Posted in category Blackhat
Been using a certain proxy finder lately, after lengthy testing you get lots of dead or not anonymous proxies. Testing these one by one with back to back curl calls is very time inefficient (testing 150 proxies even at 1 second a piece is going to take over 150 seconds). So I’ve wrote a nice little function that uses the curl_multi functions to run the calls simultaneously.
I setup a simple script on another server that simply echos ‘Hi’. This script will query a url and test the output vs ‘Hi’ (of course you can change it to whatever you like).
I’m hung over as fuck, it’s fully commented, have fun.
<?php
function checkProxies($proxies){
//$proxies is an array of proxies in format ip:port,username:password
$url = 'http://someplace.tld/testphp.php'; //url to query
$return = 'Hi'; //expected reply
$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 == $return){ //check the data returned vs what we expect
echo $i . '. Good Proxy: ' . $proxies[$i] . '<br /><br />';
$proxylist[$a] = $proxies[$i]; //it's a good proxy add it to our list
$a++;
} else echo $i . '. Bad Proxy: ' . $proxies[$i] . '<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
$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
?>
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.






















Georgie says:
April 15th, 2010 at 3:52 pm
Looks similiar to mine but II like to test if a proxy can do POST requests as well, and also just run the IP through maxmind to see where its from
Freeman says:
June 16th, 2010 at 2:50 am
?????? ????! thomas@sotkashop.ru” rel=”nofollow”>……
? ?????????,…
REVIEW IT BEFORE YOU BUY IT!!! says:
January 17th, 2011 at 9:51 am
**YOUTUBE VIDEO REVIEWS ON THE HOTTEST ELECTRONICS OUT**…
#1 SITE FOR THE LATEST REVIEWS ON THE HOTTEST TECHNOLOGY HITTING THE MAINSTREAM!…
Letmewatchthis says:
December 6th, 2011 at 5:12 am
Watch movies online free…
this is a really good post for me. Will have to concur that you are an individual of the finest blogger i actually read. thank you for submitting…