[英]How can I tell if a machine on my network is on with PHP?
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. 我想写一个类似于企业网络控制台的PHP脚本,但是对于PC和设备的局域网而不是服务器的WAN。
I want to be able to check if the PC's, Copiers etc are connected to the network. 我希望能够检查PC,复印机等是否连接到网络。 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?
我想知道即使它们已关闭,但这是不可能的,因为PC会忽略数据包,除非它是一个唤醒lan数据包,对吗?
What is the best way to check if a PC is on or off? 检查PC是打开还是关闭的最佳方法是什么? I used
fSocketOpen()
to test the servers however most of the PC's aren't servers. 我使用
fSocketOpen()
来测试服务器,但大多数PC都不是服务器。 They respond to pings but don't have ports open for connections, meaning PHP'ss fSocketOpen()
won't work but pinging does. 他们响应ping但没有端口打开连接,这意味着PHP
fSocketOpen()
不起作用,但ping操作。
You can use system commands and catch the stdout for results. 您可以使用系统命令并捕获stdout以获得结果。
Just make a search for PHP's popen ( http://uk3.php.net/popen ) examples. 只需搜索PHP的popen( http://uk3.php.net/popen )示例。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.