Changeset 33
- Timestamp:
- Jul 22, 2008, 5:55:42 PM (16 years ago)
- Location:
- sample/hadoop-0.16/tw/org/nchc/code
- Files:
-
- 1 added
- 9 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/hadoop-0.16/tw/org/nchc/code/SnortBase.java
r32 r33 206 206 207 207 public static void main(String[] args) throws IOException { 208 String table_name = " apache-log2";208 String table_name = "snort"; 209 209 String dir = "/user/waue/apache-log"; 210 210 -
sample/hadoop-0.16/tw/org/nchc/code/SnortParser.java
r32 r33 15 15 import java.io.IOException; 16 16 import java.text.ParseException; 17 import java.util.StringTokenizer;18 17 import java.util.regex.Matcher; 19 18 import java.util.regex.Pattern; 20 19 21 20 public class SnortParser { 22 private String logData = new String(); 23 private BufferedReader fi ; 24 private BufferedWriter fw ; 25 public SnortParser(String in, String ou) throws IOException { 26 fi = new BufferedReader(new FileReader(new File(in))); 27 fw = new BufferedWriter(new FileWriter(new File(ou))); 21 private String logData = new String(); 22 23 private String in; 24 25 private String ou; 26 27 public SnortParser(String in, String ou) { 28 this.in = in; 29 this.ou = ou; 28 30 } 29 31 30 public static boolean isIpAddress(String inputString) { 31 StringTokenizer tokenizer = new StringTokenizer(inputString, "."); 32 if (tokenizer.countTokens() != 4) { 33 return false; 34 } 35 try { 36 for (int i = 0; i < 4; i++) { 37 String t = tokenizer.nextToken(); 38 int chunk = Integer.parseInt(t); 39 if ((chunk & 255) != chunk) { 40 return false; 41 } 42 } 43 } catch (NumberFormatException e) { 44 return false; 45 } 46 if (inputString.indexOf("..") >= 0) { 47 return false; 48 } 49 return true; 32 public SnortParser() { 33 this.in = "/var/log/snort/alert"; 34 this.ou = "~/parseSnort.log"; 50 35 } 51 36 52 37 public void snortParser(String line, int i) throws ParseException, 53 38 Exception { 54 String[] data 39 String[] data; 55 40 Pattern patten_line; 56 Matcher matcher; 41 Matcher matcher; 57 42 switch (i) { 58 43 case 1: … … 81 66 data = new String[number]; 82 67 for (int j = 0; j < number; j++) { 83 data[j] = matcher.group(j +1);84 this.logData += (data[j] +";");68 data[j] = matcher.group(j + 1); 69 this.logData += (data[j] + ";"); 85 70 } 86 71 87 72 } 88 73 89 74 } 90 void parseToLine() throws IOException,ParseException,Exception {91 75 76 void parseToLine() throws IOException, ParseException, Exception { 77 BufferedReader fi = new BufferedReader(new FileReader(new File(in))); 78 BufferedWriter fw = new BufferedWriter(new FileWriter(new File(ou))); 92 79 String line = null; 93 80 int count = 0; 94 95 81 do { 96 String tmp = this.fi.readLine();82 String tmp = fi.readLine(); 97 83 if (tmp == null) { 98 84 break; 99 } else if(count < 4){85 } else if (count < 4) { 100 86 line = tmp; 101 //System.out.println(line);102 snortParser(line, count +1);103 count 104 } else if(count ==4 ){105 count 106 } else if (count == 5){107 this.fw.write(this.logData.toString() + "\n");108 this.logData = "" 87 // System.out.println(line); 88 snortParser(line, count + 1); 89 count++; 90 } else if (count == 4) { 91 count++; 92 } else if (count == 5) { 93 fw.write(this.logData.toString() + "\n"); 94 this.logData = ""; 109 95 count = 0; 110 } 111 else 112 { 96 } else { 113 97 System.err.print(" Error ! "); 114 return 98 return; 115 99 } 116 100 } while (true); 117 this.fw.flush();118 this.fw.close();101 fw.flush(); 102 fw.close(); 119 103 120 104 } 105 121 106 public static void main(String[] args) throws ParseException, Exception { 122 107 String in = new String("/home/waue/Desktop/alert"); 123 108 String ou = new String("/home/waue/Desktop/bb"); 124 SnortParser a = new SnortParser(in, ou);109 SnortParser a = new SnortParser(in, ou); 125 110 a.parseToLine(); 126 111 }
Note: See TracChangeset
for help on using the changeset viewer.