Page 1 of 1
Checking to see if a computer is online?
Posted: Sun Jun 16, 2002 1:59 am
by CodyLoco
How can I make a script to see if a computer is online, I was thinking of pinging the computer but I cant figure out how. I tried this but it just gave me aborted.
<?php
$myShellString = "netstat -n -a | grep 24.67.64.93:1139 |
wc -l";
$myStatus = shell_exec($myShellString);
echo " $myStatus ";
if ($myStatus = 0) {
echo "Server is Online";
} elseif ($myStatus = 1) {
echo "Server Offline 1";
} elseif ($myStatus = 2) {
echo "Server Offline 2";
} else {
echo "Server Detect Error";
};
?>
Posted: Sun Jun 16, 2002 10:29 am
by jason
Have you tried sing the backticks?
Posted: Mon Jun 17, 2002 12:48 am
by volka
how about a simple
Code: Select all
exec ("ping $host",$notWanted,$retval);
if($retval==0)
// host on
else
// host off
?
Posted: Mon Jun 17, 2002 2:10 am
by Peter
I believe you could also use sockets, because a friend of mine used specify if his ftp was up or not on his downloads page.

Posted: Mon Jun 17, 2002 8:36 am
by CodyLoco
I tried ping but it wont let me ping out ack, so I need to try something else, btw, the computer i wanna check for onlineliness is on WinXP
Posted: Mon Jun 17, 2002 8:53 am
by e+
Will your host not let you ping at all (have you tried pinging the bbc for example)? If it is you can always ask your host to turn it back on, stranger things have happened.
Is the windows xp machine set up to serve pages? If it is you could always go about it back to front and have the site try to collect a file or image etc from the windows xp box. If it can't get the file the box is not online. Bit of a clunky solution though

.
Posted: Mon Jun 17, 2002 8:58 am
by volka
any open socket you may misuse? i.e.
Code: Select all
$sd = fsockopen ( $host, 445, $errNo, $errStr, 4);
if ($errNo != 0)
print('offline '.$errNo);
else
fclose($sd);
(DAMIT, it's open on my box, too

)
Posted: Mon Jun 17, 2002 9:22 am
by e+
XP's cruddy firewal blocks that port (and the few I've tested) so if you have that running you'll have no luck.

(maybe XP's firewall isn't as bad as I thought)