Reputation: 299
I want to write a PHP script similar to Enterprise Network Console, but for a LAN of PC's and devices instead of a WAN of servers.
I want to be able to check if the PC's, Copiers etc are connected to the network. I want to know even if they are off, however this is not possible as the PCs ignore packets unless it's a wake-on-lan packet, right?
What is the best way to check if a PC is on or off? I used fSocketOpen()
to test the servers however most of the PC's aren't servers. They respond to pings but don't have ports open for connections, meaning PHP'ss fSocketOpen()
won't work but pinging does.
Upvotes: 0
Views: 1016
Reputation: 699
You can use system commands and catch the stdout for results.
Just make a search for PHP's popen ( https://www.php.net/popen ) examples.
echo run('ping 192.168.1.5');
function run($command) {
$command .= ' 2>&1';
$handle = popen($command, 'r');
$log = '';
while (!feof($handle)) {
$line = fread($handle, 1024);
$log .= $line;
}
pclose($handle);
return $log;
}
Upvotes: 2