【问题标题】:Call to system's arp command fails with shell_execshell_exec 调用系统的 arp 命令失败
【发布时间】:2013-08-26 09:57:04
【问题描述】:

我在 Google 中搜索了很长时间,但没有找到我想要的东西。我在办公室的不同建筑物中有一个本地业务网络应用程序。我的员工将在本地网络中通过无线设备和台式计算机使用此应用程序。 但我只想让他们通过有限的设备和机器访问。

我可以通过将它们的 IP 地址传递给arp 来获取连接设备的 MAC 地址,例如:

arp -n 192.168.10.12

在终端中。

但是当我在 php 脚本中运行相同的命令时,我无法得到任何输出

$output = shell_exec('arp -n 192.168.10.12'); echo "<pre>$output</pre>";

我在shell_exec函数中尝试了一些诸如ls -l /var/www之类的命令,这些命令在命令行中的显示是一样的。所以我的问题是为什么我不能运行arp -n ipaddress 命令以及如何运行它。

我无法通过路由器检查 MAC 地址,因为我的业务客户来我办公室时喜欢使用我的网络。

提前致谢。

我关注了this链接。

【问题讨论】:

  • 看看我在这里提供的 MAC 地址的解决方案:stackoverflow.com/questions/18401945/…
  • 我也有同样的问题。 /usr/sbin/arp -na 给出了我想要的列表,但 exec('/usr/sbin/arp -na') 给出了空结果。 php 中的 exec('whoami') 给出的结果与终端中的 whoami 相同。

标签: php mac-address shell-exec


【解决方案1】:

我很确定 www-user 不允许使用 arp 命令或引用完整路径。

使用其完整路径,例如/usr/sbin/arp

然后它要么工作要么没有许可。如果没有许可, 搜索sudo 并让www-user 访问arp

dan@big:/root$ /usr/sbin/arp
Address                  HWtype  HWaddress      Flags Mask            Iface
xxxx.xx.xx.xxxx  ether   00:00:XX:00:01:XX      C                     eth0

dan@big:/root$ arp
bash: arp: command not found

【讨论】:

  • 感谢 DanFromGermany,在您的帮助下我得到了它。但问题是返回 $macAddr $ipAddress=$_SERVER['REMOTE_ADDR']; echo $ipAddress; echo "&lt;pre&gt;".get_mac($ipAddress)."&lt;/pre&gt;"; function get_mac($ipAddress){ $macAddr=false; $output = shell_exec('/usr/sbin/arp'); $lines=explode("\n", $output); foreach($lines as $line){ $cols=preg_split('/\s+/', trim($line)); if ($cols[0]==$ipAddress) { $macAddr=$cols[2]; } } return $macAddr; } 需要 10 秒才能获得更好的性能吗?无论如何谢谢。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-24
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 2015-02-21
  • 1970-01-01
  • 2015-01-01
相关资源
最近更新 更多