/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import java.io.*;
import java.text.*;
import java.util.*;
public class Untitled1 {
public Untitled1() {
}
public static void main(String[] args) {
Untitled1 untitled11 = new Untitled1();
try{
File f = new File("ex0301.log");
File f2 = new File("ex0301.log.new");
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream(f2);
DataInputStream dis = new DataInputStream(fis);
DataOutputStream dos = new DataOutputStream(fos);
String s = dis.readLine();
while (s != null ){
if (!s.startsWith("#")){
try{
StringTokenizer str = new StringTokenizer(s);
String date = str.nextToken();
String time = str.nextToken();
String ip = str.nextToken();
String skip = str.nextToken();
String get = str.nextToken();
String url = str.nextToken();
String status = str.nextToken();
String bytes = str.nextToken();
skip = str.nextToken();
String port = str.nextToken();
String agent = str.nextToken().replace('+',' ');
skip = str.nextToken();
String referer = str.nextToken();
String goodUrl = "GET " + url + " HTTP/1.1";
SimpleDateFormat sdf = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss +1300]");
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt = sd.parse(date + " " + time);
long ttime = dt.getTime();
ttime+=46800;
dt = new Date(ttime);
String newDate = sdf.format(dt);
String newLine = ip + " - - " + newDate + " \"" + goodUrl + "\" " + status + " " + bytes + " \"" + referer + "\" \"" +agent + "\"";
//System.out.println(newLine);
dos.writeBytes(newLine+"\n");
}catch(Exception e){
e.printStackTrace();System.out.println("corrupt");
//System.exit(0);
}
}//if
s = dis.readLine();
}
dos.close();
fos.close();
dis.close();
fis.close();
//string tokenize on space
// date time ip skip get url code bytes skip port browser skip referer
// ip skip skip [date time] get+http/1.1 code bytes referer browser
}catch(Exception ee ){ee.printStackTrace();}
}
}
/*
good
203-167-180-148.dialup.clear.net.nz - - [27/Feb/2003:16:02:21 +1300] "GET /icons/flags/fr.png HTTP/1.1" 304 0 "http://www.geosoft.co.nz/cgi-bin/awstats.pl?config=geo&output=lasthosts" "Opera/6.0 (Linux 2.4.2-2 i586; U) [en]"
203-167-180-148.dialup.clear.net.nz - - [27/Feb/2003:16:02:21 +1300] "GET /icons/flags/de.png HTTP/1.1" 304 0 "http://www.geosoft.co.nz/cgi-bin/awstats.pl?config=geo&output=lasthosts" "Opera/6.0 (Linux 2.4.2-2 i586; U) [en]"
203-167-180-148.dialup.clear.net.nz - - [27/Feb/2003:16:02:21 +1300] "GET /icons/flags/es.png HTTP/1.1" 304 0 "http://www.geosoft.co.nz/cgi-bin/awstats.pl?config=geo&output=lasthosts" "Opera/6.0 (Linux 2.4.2-2 i586; U) [en]"
209.167.50.22 - - [27/Feb/2003:16:03:18 +1300] "GET /robots.txt HTTP/1.1" 404 330 "www.seventwentyfour.com/" "LinkWalker"
203-167-180-148.dialup.clear.net.nz - - [27/Feb/2003:15:55:32 +1300] "GET /nzmaps/servlet/nz.co.geosoft.servlets.CreateMap450?random=0.3035072606248147 HTTP/1.1" 200 30652 "http://www.geosoft.co.nz/nzmaps/servlet/nz.co.geosoft.dataimport.NewZealandMaps?action=chose&street=DOWLING&auth=DUNEDIN+CITY&suburb=DUNEDIN+CENTRAL" "Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.0.0) Gecko/20020612"
203-167-180-148.dialup.clear.net.nz - - [27/Feb/2003:15:55:32 +1300] "GET /nzmaps/servlet/nz.co.geosoft.servlets.CreateMap?random=0.17268159078034995 HTTP/1.1" 200 19716 "http://www.geosoft.co.nz/nzmaps/servlet/nz.co.geosoft.dataimport.NewZealandMaps?action=chose&street=DOWLING&auth=DUNEDIN+CITY&suburb=DUNEDIN+CENTRAL" "Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.0.0) Gecko/20020612"
203-167-180-88.dialup.clear.net.nz - - [27/Feb/2003:15:59:18 +1300] "GET /servlet/nz.co.geosoft.dataimport.MainFrame?action=search HTTP/1.1" 404 362 "http://au.google.yahoo.com/bin/query_au?p=online+maps&y=nz&h=w&hc=1&hs=18" "Mozilla/4.0 (compatible; MSIE 5.21; Mac_PowerPC)"
bad
2002-04-16 07:42:27 210.54.196.98 - GET /images/logo.gif 200 3217 703 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - http://www.geosoft.co.nz/
2002-04-16 07:56:33 210.54.199.2 - GET /images/ 403 334 0 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - -
2002-04-16 07:56:37 210.54.199.2 - GET /images/ 403 334 16 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - -
2002-04-16 08:01:44 210.54.199.2 - GET /scripts/isapi_srun.dll/caucho-status 404 623 0 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - -
2002-04-16 11:33:53 210.54.197.246 - GET /index.html 304 196 16 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - -
2002-04-16 11:33:53 210.54.197.246 - GET /images/logo.gif 304 142 0 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - http://www.geosoft.co.nz/
2002-04-16 11:47:36 210.54.197.246 - GET /snappers/ 403 334 0 80 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) - -
*/