hello. i am doing a project about implementing the linux route command with php. i have managed to see the IP tables using route but the problem now is implementing route add / route del. i have searched the web and came up with some examples but none of them work. i am running fedora 6 and have stopped SElinux since i read somewhere that it may give trouble with user rights and all.
here are some of the examples i have tried:

$answer = system("route del 192.168.183.5",$ret_val);
echo "test ".$ret_val;

with this one i get a return value of 7 which i believe it's an error code since it should be 0, couldn't find it anywhere

$add = shell_exec("/sbin/route del 192.168.183.5");

echo `route del 192.168.183.4`;

$defaultRoute = shell_exec("route add 192.168.183.8 gateway 192.168.183.2");

i even tried one with sudo and still nothing.

can anyone please help me since i am really puzzled about this. thanks

try "system()" command to get the return value.

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>

try "system()" command to get the return value.

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>

i have already tried system, i gave one such example above. it works with other commands like the one u listed and even some root commands like ifconfig but still not with what i need. thanks anyway i'm still hoping for a breakthrough

how about if you put that command in one script.

example: route-eth0-add and route-eth0-del
use "chmod" to make it executable.

then call that script in your system() in php?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.