...

View Full Version : checking the target server is on or off



joonstar
09-13-2003, 10:21 AM
<?php
$read = @fopen("http://220.89.242.117:8500","r" );

if (!$read){
header('Location: sorry.php');
}
else{
fclose($read);
header('Location: http://220.89.242.117:8500');
}
?>

The above code is intended for nex two conditions.

If the remote target server is dead, go to sorry.php.
If the remote target server is alive, go to the server.



But the result of the above code is;

(1) when the target server is off, the check page try to find the target
server for a long time, and it finally says it can't find the target server.

(2) when the target server is on the way of booting, the check page goes to
sorry page.

(3) when the target server is fully booted, the check page goes to the
target server page.

The problem happens when the target server is off.
Do you have more correct code for it?

Thanks in Advance

Nightfire
09-13-2003, 01:35 PM
(2) when the target server is on the way of booting, the check page goes to sorry page.

There's no way to detect if the server is online if the server isn't connected to the net yet. It will always go to the sorry page



Try this code



<?php
//Autor: Antonio Leal Elizondo 12/Ago/03
//e-mail: invasor@hotmail.com
// This script pings a machine and checks if it's alive or not.
// It can run a command in case the machine is not answering

// Variables
//-------------------------
$unix = 1; //Put 1 here if you are using a UNIX machine
$windows = 0; //Put 1 here if you are using a Windown machine


$unix = (bool) $unix;
$win = (bool) $windows;

$count= 3; // Number of times to ping
$host = "177.17.31.165"; // IP of the remote server
$find = "Tiempo de espera agotado"; // String to look for
$shell= "pwd"; // Command to execute if the machine does not answer.
$findUnix="0 packets received";


// Replaced nonvalued characters
$host= preg_replace ("/[^A-Za-z0-9.]/","",$host);
echo("Resultados: ");

//Check the IP
if ($unix==1){
$comm="ping -t $count $host";
$res=shell_exec($comm);
}else{
$comm="ping -n $count $host";
$res=shell_exec($comm);
}
// system("killall ping");// Kill all pings in case they exist.
//echo $res;

$flag= strstr($res,$findUnix);
$long=strlen($flag);
if ($long<>0){
echo "\n An error has occured at $host\n ";
echo date("D F Y h:i a");
echo "\n Executng auxiliary command \n ";
$res=shell_exec($shell);
echo $res;
}else{
echo "\n There are no problems with $host \n";
echo date("D F Y h:i a"). "\n" ;
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum