01: package tools;
02:
03: import java.io.*;
04: import java.net.*;
05: import java.util.StringTokenizer;
06:
07: public class LogTool {
08:
09: public static String getHost(String ip) {
10: try {
11: return java.net.InetAddress.getByName(ip).getHostName();
12: } catch (java.net.UnknownHostException e) {
13: return ip;
14: }
15: }
16:
17: public static void main(String[] args) {
18: try {
19: LineNumberReader reader = new LineNumberReader(
20: new InputStreamReader(System.in));
21: while (true) {
22: String line = reader.readLine();
23: if (line == null) {
24: return;
25: }
26: StringTokenizer tok = new StringTokenizer(line, "\t");
27: String time = tok.nextToken();
28: String ip = tok.nextToken();
29: tok.nextToken();
30: tok.nextToken();
31: tok.nextToken();
32: tok.nextToken();
33: String href = tok.nextToken();
34: String ref = tok.nextToken();
35: String browser = tok.nextToken();
36: if (href.indexOf("/images") >= 0) {
37: continue;
38: }
39: System.out.println(time + " " + href);
40: System.out.println("from: " + getHost(ip));
41: System.out.println("with: " + browser);
42: if (ref.indexOf("njet.org") == -1 && !ref.equals("-")) {
43: System.out.println("link: " + ref);
44: }
45: System.out.println();
46:
47: /*System.out.println("time :"+time);
48: System.out.println("ip :"+ip);
49: System.out.println("href :"+href);
50: System.out.println("ref :"+ref);
51: System.out.println("browser:"+browser);*/
52:
53: }
54: } catch (Throwable t) {
55: }
56: }
57:
58: }
|