[英]shell_exec not working with nmap command
I got a problem with the shell_exec
php function, here is a example code: 我的
shell_exec
php函数出现问题,下面是示例代码:
$output = shell_exec('nmap -PS80 -n -oG - --send-ip 11.11.11.11');
if ( $output )
{
echo "Output found...";
}
else
{
var_dump( $output );
}
It does return: NULL
, but when I change the shell_exec
command to the following: 它的确返回:
NULL
,但是当我将shell_exec
命令更改为以下命令时:
$output = shell_exec('echo 1');
then the output is: Output found...
so its working properly, and there is no problems with permissions or safe mode (which is off , by the way). 那么输出为:
Output found...
使其正常工作,并且权限或安全模式没有问题(顺便说一下,它是off)。
It is having a problems with execute the nmap
command. 执行
nmap
命令时遇到问题。 I've check that command in the shell command line in putty and its working properly: 我已经在腻子的shell命令行中检查了该命令,它是否正常工作:
# nmap -PS80 -n -oG - --send-ip 11.11.11.11
# Nmap 5.61TEST2 scan initiated Tue Feb 28 13:55:41 2012 as: nmap -PS80 -n -oG - --send-ip 11.11.11.11
# Nmap done at Tue Feb 28 13:55:43 2012 -- 1 IP address (0 hosts up) scanned in 0.04 seconds
So where is the problem? 那么问题出在哪里呢?
Try to specify full path to nmap like /usr/local/bin/nmap
. 尝试指定nmap的完整路径,例如
/usr/local/bin/nmap
。 PHP might not know about nmap location. PHP可能不知道nmap的位置。 Enjoy!
请享用!
You might want to resort to exec()
instead, which gives you greater error diagnostics: 您可能希望改为使用
exec()
,这为您提供了更多的错误诊断:
// Capture outout from STDERR as well
$command = "nmap ... 2>&1";
exec($command, $output, $return_var);
// If return code is not zero, the command failed
if ($return_var != 0)
{
// dump all output, including error messages
var_dump($output);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.