Hello everyone, I was wondering if you guys can help me out. I'm stuck on this assignment =(.......
This is what I need to do...
Write a program that analyzes a web server's log file to determine which computers have attempted to access that web server the most. Any class in the Java standard library is available for use on this assignment.
So far this is what I got...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.*; public class logfile { public static void main(String[] args) throws IOException { String filename; //file name String log; String s; Map <String, Integer> name = new HashMap <String, Integer>(); //create scanner object for keyboard input Scanner keyboard = new Scanner(System.in); System.out.println("Enter a log file to be analyzed"); filename = keyboard.nextLine(); FileReader f = new FileReader(filename); BufferedReader inputFile = new BufferedReader(f); log = inputFile.readLine(); while(log != null) { Scanner read = new Scanner(f); // if we put this it will print out all the info inside the the logs /* * while(log! = null) * { * System.out.println(log); * * log = input.File.readLine(); * } */ while(read.hasNext()) { while (read.hasNext()) if(read.next().contains("[client")) break; if(read.hasNext()) { s = read.next(); s = s.substring(0, s.length()- 1); System.out.println(s); } read.nextLine(); } log = inputFile.readLine(); } System.out.println("Found " + "_______" + " unique IP addresses."); System.out.println("The most suspicious are: "); System.out.println() } }