Page 1 of 1
running `iwlist scan` inside php on Linux server[SOLVED]
Posted: Wed Feb 21, 2007 10:11 am
by Shucklak
Hello, I am trying to tun `iwlist scan` inside some php but I am having some trouble. I have tried all the following without any results:
Code: Select all
$output = exec("iwlist scan");
$output = `iwlist scan`;
$output = shell_exec("iwlist scan");
I have even tried making "iwlist scan" into an executable file called "scan" and then running the above with "scan" or "./scan" and it did not work.
Any help would be greatly appreciated.
Posted: Wed Feb 21, 2007 12:30 pm
by volka
please try
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
exec("iwlist scan", $output, $status);
echo '<pre>', var_dump($status), ' : ', var_export($output), "</pre>\n";
Posted: Fri Feb 23, 2007 11:11 am
by Shucklak
The exact output of that was:
int(127)
: array (
)
Is it possible it is a permission problem and that is why I cannot run the program?
Posted: Fri Feb 23, 2007 2:33 pm
by volka
May be a permission problem. But I guess the php script is running on a different account than you're logged in and it can't find iwlist because of a different PATH setting.
Please try.
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$output = array();
exec("which iwlist 2>&1", $output, $status);
echo '<pre>', var_dump($status), ' : ', var_export($output), "</pre>\n";
$output = array();
exec("doesnotexist1234 2>&1", $output, $status);
echo '<pre>', var_dump($status), ' : ', var_export($output), "</pre>\n";
Posted: Fri Feb 23, 2007 2:57 pm
by Shucklak
The output from that was:
int(1)
: array (
)
int(127)
: array (
0 => 'sh: doesnotexist1234: command not found',
)
Posted: Fri Feb 23, 2007 3:08 pm
by volka
ah, so the 2>&1 is working with exec() and
which does not find iwlist.
type
in your own shell. It prints the absolute path to the file you would use by typing
iwlist.
Use this path in your php script
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$output = array();
exec("/path/you/got/from/which/to/iwlist 2>&1", $output, $status);
echo '<pre>', var_dump($status), ' : ', var_export($output), "</pre>\n";
Posted: Fri Feb 23, 2007 3:29 pm
by Shucklak
That did it!
Wow I can't thank you enough. I've spent countless hours working on this.
Thanks!