我有一个文本文件,其中包含来自myip.ms的178.000行列入黑名单的IP(12 MB),格式为:
1.2.81.113 # 2014-09-10, 1.2.81.113, CHN, 51
1.2.82.108 # 2014-09-10, 1.2.82.108, CHN, 51
1.2.83.179 # 2014-09-11, 1.2.83.179, CHN, 51
1.2.86.210 # 2014-09-07, 1.2.86.210, CHN, 51
1.2.109.22 # 2014-09-06, 1.2.109.22, CHN, 51
现在,我需要在每行之前添加“ Require not ip”,如下所示:
Require not ip 1.2.81.113 # 2014-09-10, 1.2.81.113, CHN, 51
Require not ip 1.2.82.108 # 2014-09-10, 1.2.82.108, CHN, 51
Require not ip 1.2.83.179 # 2014-09-11, 1.2.83.179, CHN, 51
Require not ip 1.2.86.210 # 2014-09-07, 1.2.86.210, CHN, 51
Require not ip 1.2.109.22 # 2014-09-06, 1.2.109.22, CHN, 51
如何以最小的努力来达到我的最佳配置,以达到我的apache配置?或者是否有更好的方法来包括黑名单?
<Directory /var/www/>
<RequireAll>
Require all granted
# IP Blacklists
Include full_blacklist_database.txt
</RequireAll>
</Directory>
在Java中,您可以执行以下操作:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JOptionPane;
public class StringAppender {
public static void main(String[] args) {
String fileIn = JOptionPane.showInputDialog("Enter the path to the file");
try{
if(new File(fileIn).exists()){
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(fileIn));
String tmp;
while((tmp = br.readLine()) != null)
sb.append("Require not ip " + tmp + "\n");
br.close();
BufferedWriter out = new BufferedWriter(new FileWriter(fileIn + ".new.txt"));
out.write(sb.toString());
out.close();
JOptionPane.showMessageDialog(null, "Done! New file saved as: " + fileIn + ".new.txt");
}else{
JOptionPane.showMessageDialog(null, "Requested file doesn't exist!");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Unable to perform changes!");
}
}
}
预编译的版本可以在此处下载。要将cd运行到dir并执行java StringAppender
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句