ok, I tried them and other IP's I found on other sites with similar service, but for some reason cURL would fail most of the time.
For the random IPs above, I've got 2 dead ones and one 403 with redirection. Codes I used is the same as your code above except I added this..
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL, 1);
We can also check if the cURL is reading something by passing the fetched data to a PHP function called stripos or even better pregmatch.
if (preg_match("/html/i", $data)) {
echo 'IP is alive';
} else {
echo 'IP is dead';
}
## I have seen some other guys do it like this
$countX = stripos($data,'</html>');
if($countX > 0 ){
echo 'It is alive';
}
else{
echo 'Not available';
}
There is a class written by Stanislav in PHPclass.org that looks pretty promising. Another one is written by Alexey , this may need minor work, but it is looking pretty good because of the Ping functions, instead of sending the cURL right away.
UPDATE: I forgot mention there is a PHP exec that can be very helpful in knowing if the IP is alive or not. If you run this code..
function GetPing($ip=NULL) {
if(empty($ip)) {$ip = $_SERVER['REMOTE_ADDR'];}
if(getenv("OS")=="Windows_NT") {
$exec = exec("ping -n 3 -l 64 ".$ip);
return end(explode(" ", $exec ));
}
else {
$exec = exec("ping -c 3 -s 64 -t 64 ".$ip);
$array = explode("/", end(explode("=", $exec )) );
return ceil($array[1]) . 'ms';
}
}
echo GetPing('42.62.5.106');
That should give you at least something, now, you can use the integer response of the ping function above to eliminate the dead ones from the live one.
Although the ping function will not really check on the port, it will confirm that the IP is up and running. Run the ping function first for the IP and then run cURL to see if there is a redirect. Otherwise the positive ping result should be sufficient. The above IP returned 176 ms in ping function, but would return 302 with redirect with cURL.
Reference ping.