0

I want to scan from my PHP script, which enters the terminal of my Linux computer. I installed the arp-scanner and tried the following index.php file:

<?php
echo shell_exec("sudo arp-scan -l");
?>

When I enter the IP address in the browser, nothing happens. What am I missing?

Thanks in advance~

M.

Michelle Turner
  • 314
  • 5
  • 22
  • 1
    `shell_exec()` returns null if an error occurred. Check that the user (which is the user the web server uses, typically www-data for Apache) have access to execute that command on the server. – M. Eriksson Jul 20 '17 at 14:02
  • 2
    sudo most likely does not make sense in this context. When you enter the ip address into the browser, the script runs as the web-server user. Normally this user does not have super user access. Additionally, if you really really want to use sudo - this question might help. https://stackoverflow.com/questions/3173201/sudo-in-php-exec – Scott Jul 20 '17 at 14:02

1 Answers1

-1

You can use the following command to make it run

$password = 'root';
$cmd = "echo '$password' | sudo -S arp-scan -l";
Chetan Soni
  • 784
  • 1
  • 6
  • 11