Reputation: 4539
I want to get all the router list of my network using php on linux. I have tried php exec and system function but it is give only one router in output.
How to get whole list of router?
$last_line = system('iwlist scan', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
$last_line = system('iwlist scan | grep ESSID', $retval);
echo '
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
Upvotes: 0
Views: 2333
Reputation: 6871
Use passthru to retrieve all of the output.
You must understand that there are different output streams to consider here:
iwlist
will probably produce text on stdout and stderr (due to other interfaces that don't support wireless)grep
will only receive the output through the pipe from stdoutpassthru
will receive both stdout and stderr from iwlist
and grep
.You can redirect the output so that you only get the successful output that has been grep'ed. The whole thing then becomes:
echo passthru('iwlist scan 2>/dev/null | grep ESSID');
Upvotes: 1