Home > Backend Development > PHP Tutorial > php一致改防火墙配置里的ip

php一致改防火墙配置里的ip

WBOY
Release: 2016-06-13 10:30:20
Original
778 people have browsed it

php统一改防火墙配置里的ip

<?php /** * 工具文件 * 目的在:修改一个防火墙的ip * 前提:文件中有一句 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -s 117.89.152.141  -j ACCEPT * 前提2:存在一个文件例如/home/iptables.bak *  * 调用示例 * php change_ip.php 202.111.11.1 *  */if (count($argv) <= 1 ) {        echo "请带上新的ip参数:例如 ipchange 222.222.222.22\n";    exit;}$arg = $argv[1];$filename = '/home/iptables.bak';$content = file_get_contents($filename);$old_ip = preg_replace('/^.+3306\s+-s\s+(\d+\.\d+\.\d+\.\d+)\s+.+$/s','$1',$content);$content = preg_replace('#'. $old_ip .'#', $arg, $content);file_put_contents($filename, $content);//system('iptables-restore '.$filename);echo $filename .': '.  $old_ip . ' => ' . $arg."\n";
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template