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";
相关推荐
Wepe0 2020-10-30
Lostinthewoods 2020-10-29
hickwu 2020-10-23
focusforce 2020-10-10
summerinsist 2020-08-21
winki 2020-08-19
89284553 2020-07-17
大老张学编程 2020-07-04
xiaohouye 2020-06-28
lizhengfa 2020-06-26
Aveiox 2020-06-25
clamzxf 2020-06-16
kerson 2020-06-16
zhangwentaohh 2020-06-14
学峰的学习笔记 2020-06-11
linuxalienyan 2020-06-11