Is there anyway that a PC can be tested by a PHP script to see if it is on the network (switched on) and then display a customisable message to say if it is on or off?
@paul_harrisauthorApr 13.2007 — #I have the PCs networked via a router to a PC (acting as a server) with IIS on it. You mentioned pinging the PCs. What script can I use to do this and get the script to say a customisable message such as "Computer x is online"?
@bathurst_guyApr 13.2007 — #Here's a quick and nasty[code=php]<?php $os = "mac"; // What OS will this PING be running on? win = Windows, mac = Macintosh/Linux $ips = array( // Set all your IP addresses here and a name "192.168.1.1" => "Gateway", "192.168.1.2" => "Webserver", "192.168.1.3" => "Another" );
// You dont need to edit below here
$count = ""; //disinfect $ip = "";
if($os == "win"){ $count = "-n 1"; // sets to ping only once (because otherwise this script can take a while!) $ereg = "Lost = 0"; }else{ $count = "-c1"; // sets to ping only once (because otherwise this script can take a while!) $ereg = "0% packet loss"; } echo "<pre>"; foreach($ips as $ip => $name){ $result = ping $count $ip; // run PING $test = ereg($ereg,$result); // Check results echo "Computer "$name" ($ip) is "; if($test == TRUE){ // if 0% packet loss echo "alive<br>"; // YEY! }else{ // otherwise echo "dead<br>"; // BOO! } } echo "</pre>"; ?> [/code]
@paul_harrisauthorApr 14.2007 — #Thanks for the script bathurst_guy. I tried running it and changed os to Windows and put in ips but all i get is "PHP Warning: shell_exec() [function.shell-exec]: Unable to execute 'ping -n 1 192.168.0.102' in C:Inetpubwwwrootimagesping.php on line 23". Anyone got any ideas? I haven't changed anything other than the os and the ips.
@paul_harrisauthorApr 15.2007 — #Thanks for the reply. I just opened the php.ini file and used the find function to search for shell_exec. I cannot find this anywhere in the php.ini file. Do I have an old version of PHP? It is installed on a PC using IIS server for an intranet.