Checking to see if a computer is online?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CodyLoco
Forum Newbie
Posts: 2
Joined: Sun Jun 16, 2002 1:59 am

Checking to see if a computer is online?

Post 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";
};
?>
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Have you tried sing the backticks?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

how about a simple

Code: Select all

exec ("ping $host",$notWanted,$retval);
if($retval==0)
  // host on
else
  // host off
?
Peter
Forum Commoner
Posts: 28
Joined: Mon Jun 10, 2002 12:40 am
Location: Brisbane, Australia

Post 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. :)
CodyLoco
Forum Newbie
Posts: 2
Joined: Sun Jun 16, 2002 1:59 am

Post 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
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post 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 :( .
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :( )
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post 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)
Post Reply