Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to run arp command or any other s/w on linux who can show output of all mac address of computer that are connected in local area network wired connection . This command need to run apache from root . So security concern is also matter .

Prompt reply would be appreciate .

share|improve this question
add comment

2 Answers

2 ways of doing it use the exec() command within php to directly execute the request.

Or what I'd do is separate the web side from the command side totally.

Have php write a command "request" into a database table.

Have a cron script that executes a php/perl/python whatever bash script/application that will request which command to run from the db (check see if request is pending if so run specified command) and then write its result set out back into the DB.

Then have your php website display the output. So it'd go something like this:

Request (webserver) > pending db > cron check if job exists > if job exists execute requested command > return data db > webserver displays data.

How you notify the end client that a result has been returned is upto you I suggest either an iframe or an ajax check query to see if results exist in the db that haven't been "viewed" yet. Have your cron job set to run every 60 seconds for example so it'll take no longer than 60 seconds from the user requesting it to the actual result being returned.

share|improve this answer
add comment

What you need is to know how to manupilate strings!

<?php

exec("mylinuxcmd", $exitVals);

?>

for run a command, just use:

where $exitVals is na Array with the terminal output or the "mylinuxcmd", each line of output is stored in an array position!

This is an example of catching server IP`s and print them on screen:

<?php

// exec ifconfig linux command and catch exit on $arr
exec("ifconfig", $arr);



foreach($arr as $ar) {
if(strstr($ar,'inet ')){
        if(!strstr($ar,'127.0.0.1')){

        $a = explode (' ',$ar);
        echo $a[1]."\r\n";
        }
}

}
?>

Depending on your sistem ifconfig, the ip can be in different place, so $a[1] can be $a[2], etc

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.