running `iwlist scan` inside php on Linux server[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shucklak
Forum Newbie
Posts: 4
Joined: Wed Feb 21, 2007 10:07 am

running `iwlist scan` inside php on Linux server[SOLVED]

Post 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.
Last edited by Shucklak on Fri Feb 23, 2007 3:29 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
Shucklak
Forum Newbie
Posts: 4
Joined: Wed Feb 21, 2007 10:07 am

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
Shucklak
Forum Newbie
Posts: 4
Joined: Wed Feb 21, 2007 10:07 am

Post by Shucklak »

The output from that was:
int(1)
: array (
)

int(127)
: array (
0 => 'sh: doesnotexist1234: command not found',
)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ah, so the 2>&1 is working with exec() and which does not find iwlist.
type

Code: Select all

which iwlist
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";
Shucklak
Forum Newbie
Posts: 4
Joined: Wed Feb 21, 2007 10:07 am

Post by Shucklak »

That did it!
Wow I can't thank you enough. I've spent countless hours working on this.
Thanks!
Post Reply