Я пытался понять, почему я не могу заставить NMap дать мне какой-либо вывод или даже работать в этом отношении через PHP.
Вещи, которые я пробовал до сих пор:
// this doesn't return anything because it's wrong
$output = passthru('nmap -V');
echo $output;
// this returns a negated integer value
passthru('nmap -V', $output);
echo $output;
// this doesn't return anything either
$stream = popen('C:\nmap -V', 'r');
while (!feof($stream))
{
$buffer = fread($stream, 1024);
echo $buffer;
}
pclose($stream);
// this doesn't do anything as well
$output = system('C:\nmap -V');
echo $output;
// this does nothing also...
ob_start(); // start output buffering
fpassthru('C:\nmap -V'); // flush COMPLETE output of nmap
$output = ob_get_contents(); // capture output buffer contents
ob_end_clean(); // shutdown output buffers
echo $output; // echo it
.
// okay, how about we try a 'proc_open()'?
// nope, this doesn't work either. I just get a value of "command returned -1073741515"
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "errors/errors.txt", "a") // stderr is a file to write to
);
$cwd = 'errors';
$env = array('some_option' => 'aeiou');
$process = proc_open('C:/nmap -V', $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process))
{
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /errors/errors.txt
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
И многие другие, но я не получаю абсолютно НИЧЕГО от $output
. Я тоже много искал в Google, но до сих пор не могу понять. Многие примеры также, кажется, для Linux, что не помогает.
Спасибо.
passthru()
, так как эта функция в любом случае не возвращает никаких данных. - person esqew   schedule 29.04.2021passthru
. - person t0rxe   schedule 29.04.2021shell_exec()
также не обязательно ничего возвращает. - person Alex Howansky   schedule 29.04.2021proc_open
потому что вы можете указать каналы для stdin, stdout и stderr (и я сейчас работаю над проектом, используя его). - person Chris Haas   schedule 30.04.2021