求教,如何在PHP上执行iptables的命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求教,如何在PHP上执行iptables的命令相关的知识,希望对你有一定的参考价值。

我的是在ubuntu上php5,我想制作一个网页通过localhost连接之后可以通过这个网页执行iptable的各种设置命令。。。该如何做到。。。按照网上的说法,通过system(),和exec()函数可以实现,但是我试了之后发现这两个函数都无法对iptable进行修改。。。到底该如何实现或者该如何使用这两个函数,谢了
比如说在php页面上,我设置了一个按钮,点击这个按钮之后就通过exec()函数实现/sbin/iptables -L功能,即实现exec("/sbin/iptables -L");这条查询语句,拿如何把查询的结果显示在页面上,又如何通过执行exec("/sbin/iptables -t filter -A OUTPUT -p icmp -j DROP");实现对iptable的设置,这两条语句我都试过,但没作用。。。

可使用exec、system去处理,但是如果你开启了安全模式,safe mode,你只能执行 safe_mode_exec_dir 目录下的东西。
exec的函数原型为:string exec ( string $command [, array &$output [, int &$return_var ]] ),也就是说明了,持行命令完后将命令的标准输出按回车符为行终结符放入$output这个变量,将命令最终返回值放入$return_var这个变量,并返回最后一行字符
system的函数原型为:string system ( string $command [, int &$return_var ] ),持行命令完后将命令的标准输出放入$return_var这个变量或将命令最终返回值放入$return_var这个变量。并返回首行字符
参考技术A 建议使用exec去处理
但是如果你开启了安全模式,safe mode,你只能执行 safe_mode_exec_dir 目录下的东西。本回答被提问者和网友采纳
参考技术B string exec ( string $command [, array &$output [, int &$return_var ]] )
If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().
还要注意权限问题

参考资料:http://php.net/manual/en/function.exec.php

以上是关于求教,如何在PHP上执行iptables的命令的主要内容,如果未能解决你的问题,请参考以下文章

求教:运行bat文件后如何让cmd窗口自动关闭?

求教php首页上想让两张图片循环滚动代码怎么写啊

linux怎么关闭iptables linux如何关闭防火墙

求教用Notepad++编辑PHP文件的一些设置

linux怎么关闭iptables linux如何关闭防火墙

新手求教,iptables无法识别