-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFail2Ban.java
More file actions
39 lines (38 loc) · 1.37 KB
/
Copy pathFail2Ban.java
File metadata and controls
39 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Hashtable;
import java.util.Map;
import java.io.IOException;
import java.io.FileWriter;
public class Fail2Ban{
public static void main(String[] args){
Hashtable<String, Integer> ipAdresses = new Hashtable<String, Integer>();
try{
File openLogs = new File("logs_processed.txt");
Scanner readFile = new Scanner(openLogs);
while(readFile.hasNextLine()){
String[] line = readFile.nextLine().split(" ");
if(line[5].equals("Invalid")){
if (ipAdresses.containsKey(line[9])) {
ipAdresses.put(line[9], ipAdresses.get(line[9]) + 1);
} else
ipAdresses.put(line[9], 1);
}
}
readFile.close();
} catch(FileNotFoundException e) {
System.out.println("File Not Found");
}
try{
FileWriter writeLog = new FileWriter("output.txt");
for (Map.Entry<String, Integer> entry : ipAdresses.entrySet()){
if(entry.getValue() > 3)
writeLog.write(entry.getKey() + "\n");
}
writeLog.close();
}catch(IOException e){
System.out.println("An Error has occured....");
}
}
}