1

I has been searching a long time in Google but not get what I looking for. I have an local web application for business in different building of my office. My staff will use this application in local network with both wireless devices and desktop computer. But I want to give them access through only limited devices and machines.

I can get the MAC address of connected devices by passing their IP addresses to arp, for instance:

arp -n 192.168.10.12

in terminal.

But I can't get any output when I run same command in php script

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

I tried some commands such as ls -l /var/www in shell_exec function, these commands display the same as in the command line. So my question is why I can't run arp -n ipaddress command and how to run it.

I can't check the MAC address via router because my business clients like to use my network when they come to my office.

Thanks in advance.

I followed this link.

Community
  • 1
  • 1
user2710326
  • 15
  • 1
  • 5
  • Take a look into solution for MAC-addresses I've provided here: http://stackoverflow.com/questions/18401945/is-it-possible-to-restrict-php-page-to-certain-devices/18402135#18402135 – Alma Do Aug 26 '13 at 09:59
  • I have the same problem. `/usr/sbin/arp -na` gives the list I want, but exec('/usr/sbin/arp -na') gives empty result. exec('whoami') in php gives the same result as `whoami` in the terminal. – EDP Jan 17 '16 at 14:42

1 Answers1

1

I'm pretty sure the www-user is not allowed to use the arp command or reference to the full path.

Use its full path like /usr/sbin/arp.

It either works or sais no permission then. If no permission, search for sudo and let www-user access 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
Daniel W.
  • 26,503
  • 9
  • 78
  • 128
  • Thank DanFromGermany, I got it with ur help. but problem is it took 10s to return $macAddr `$ipAddress=$_SERVER['REMOTE_ADDR']; echo $ipAddress; echo "
    ".get_mac($ipAddress)."
    "; 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; }` can it be done with better performance? Anyway Thank. :)
    – user2710326 Aug 31 '13 at 14:34