日志结构如
202.108.11.232 - - [07/Jul/2005:00:00:59 +0800] "GET /sl/detail.php?actt=13&id=239552&p_id=561412 HTTP/1.1" 200 13262 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)" nbchem.com text/html "/usr/home/uz60g1/htdocs/sl/detail.php"
202.108.11.232 - - [07/Jul/2005:00:01:06 +0800] "GET /news/detail.php?id=22581 HTTP/1.1" 200 28184 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)" nbchem.com text/html "/usr/home/uz60g1/htdocs/news/detail.php"
进行分析后导入到mysql数据的辅助程序
#include<stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <time.h>
void empty(char *a[],int b)
{
int i;
for(i=0;i<b;i++)
*a[i]='';
}
main()
{
long i=0;
int j=0;
int p=1;
int k=11;
int hu=0;
long ip=0;
long yu=0;
int fly=0;
int label1,label2,label3,label4,label5;
int lab1,lab2,lab3,lab4,lab5;
int la1,la2,la3,la4,la5;
int handle;
int via=0;
double xx,xx1,xx2;
struct stat buffer;
char afile[200];
char chn[50000];
char ips[20];
char time[50];
char way[5];
char visit[100];
char filetype[50];
char time1[50];
char day[5];
char mon[6];
char yea[7];
char hou[5];
char min[5];
char sec[5];
char ok;
FILE *fp,*fa;
textcolor(k);
label1=label2=label3=label4=label5=0;
lab1=lab2=lab3=lab4=lab5=0;
la1=la2=la3=la4=la5=0;
while(1)
{
handle=open(afile,O_RDONLY);
printf("\nplease enter a file : (like f:/data/aclearcase/" target="_blank" >ccess1.c)\n");
scanf("%s",afile);
fstat(handle, &buffer);
yu=buffer.st_size;
if(yu>0)
break;
}
fp=fopen(afile,"rt");
fa=fopen("f:\ha.txt","wt+");
printf("%ld\n",yu);
for(i=0;i<yu;i++)
{
ok=fgetc(fp);
if(ok==10)
{
xx1=i;
xx2=yu;
xx=(xx1/xx2)*100;
textcolor(154);
cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%ld,%ld,%f %",ip,i,xx);
/*--init the arrays--*/
for(fly=0;fly<20;fly++)
ips[fly]='';
for(fly=0;fly<50;fly++)
time[fly]='';
for(fly=0;fly<5;fly++)
way[fly]='';
for(fly=0;fly<100;fly++)
visit[fly]='';
for(fly=0;fly<50;fly++)
filetype[fly]='';
for(fly=0;fly<50;fly++)
time1[fly]='';
for(fly=0;fly<5;fly++)
{
day[fly]='';
hou[fly]='';
min[fly]='';
sec[fly]='';
}
for(fly=0;fly<6;fly++)
mon[fly]='';
for(fly=0;fly<7;fly++)
yea[fly]='';
label1=label2=label3=label4=label5=0;
lab1=lab2=lab3=lab4=lab5=0;
la1=la2=la3=la4=la5=0;
/*--array devide start!!--*/
for(fly=0;fly<p;fly++)
{
if(label1==0)
{
if(chn[fly]==' ')
label1=1;
else
{
ips[lab1]=chn[fly];
lab1++;
}
}
else if(label2==0)
{
if(la1==0)
{
if(chn[fly]=='[')
la1=1;
}
else if(la1==1)
{
if(chn[fly]==' ')
label2=1;
else
{
time[lab2]=chn[fly];
lab2++;
}
}
}
else if(label3==0)
{
if(la2==0)
{
if(chn[fly]=='\"')
la2=1;
}
else if(la2==1)
{
if(chn[fly]==' ')
label3=1;
else
{
way[lab3]=chn[fly];
lab3++;
}
}
}
else if(label4==0)
{
if(la3==0)
{
if(chn[fly-6]=='h')
if(chn[fly-5]=='t')
if(chn[fly-4]=='d')
if(chn[fly-3]=='o')
if(chn[fly-2]=='c')
if(chn[fly-1]=='s')
if(chn[fly]=='\/')
la3=1;
}
else if(la3==1)
{
if(chn[fly]=='\"')
label4=1;
else
{
visit[lab4]=chn[fly];
lab4++;
}
}
}
}
for(la4=0;la4<lab4;la4++)
{
if(visit[la4]=='.')
la5=la4;
}
if(la5==0)
{
filetype[0]='p';
filetype[1]='h';
filetype[2]='p';
}
else
{
for(la4=(la5+1);la4<lab4;la4++)
filetype[la4-la5-1]=visit[la4];
}
for(lab5=0;lab5<lab2;lab5++)
{
if(lab5<2)
day[lab5]=time[lab5];
else if((lab5>2)&&(lab5<6))
mon[lab5-3]=time[lab5];
else if((lab5>6)&&(lab5<11))
yea[lab5-7]=time[lab5];
else if((lab5>11)&&(lab5<14))
hou[lab5-12]=time[lab5];
else if((lab5>14)&&(lab5<17))
min[lab5-15]=time[lab5];
else if((lab5>17)&&(lab5<20))
sec[lab5-18]=time[lab5];
}
if(mon[0]=='F')
if(mon[1]=='e')
if(mon[2]=='b')
{
mon[0]='0';
mon[1]='2';
mon[2]='';
}
if(mon[0]=='M')
if(mon[1]=='a')
if(mon[2]=='r')
{
mon[0]='0';
mon[1]='3';
mon[2]='';
}
if(mon[0]=='A')
if(mon[1]=='p')
if(mon[2]=='r')
{
mon[0]='0';
mon[1]='4';
mon[2]='';
}
if(mon[0]=='M')
if(mon[1]=='a')
if(mon[2]=='y')
{
mon[0]='0';
mon[1]='5';
mon[2]='';
}
if(mon[0]=='J')
if(mon[1]=='u')
if(mon[2]=='n')
{
mon[0]='0';
mon[1]='6';
mon[2]='';
}
if(mon[0]=='J')
if(mon[1]=='u')
if(mon[2]=='l')
{
mon[0]='0';
mon[1]='7';
mon[2]='';
}
if(mon[0]=='A')
if(mon[1]=='u')
if(mon[2]=='g')
{
mon[0]='0';
mon[1]='8';
mon[2]='';
}
if(mon[0]=='S')
if(mon[1]=='e')
if(mon[2]=='p')
{
mon[0]='0';
mon[1]='9';
mon[2]='';
}
if(mon[0]=='O')
if(mon[1]=='c')
if(mon[2]=='t')
{
mon[0]='1';
mon[1]='0';
mon[2]='';
}
if(mon[0]=="N")
if(mon[1]=='o')
if(mon[2]=='v')
{
mon[0]='1';
mon[1]='1';
mon[2]='';
}
if(mon[0]=='D')
if(mon[1]=='e')
if(mon[2]=='c')
{
mon[0]='1';
mon[1]='2';
mon[2]='';
}
if(mon[0]=='J')
if(mon[1]=='a')
if(mon[2]=='n')
{
mon[0]='0';
mon[1]='1';
mon[2]='';
}
for(lab5=0;lab5<19;lab5++)
{
if(lab5<4)
time1[lab5]=yea[lab5];
else if(lab5==4)
time1[lab5]='-';
else if((lab5>4)&&(lab5<7))
time1[lab5]=mon[lab5-5];
else if(lab5==7)
time1[lab5]='-';
else if((lab5>7)&&(lab5<10))
time1[lab5]=day[lab5-8];
else if(lab5==10)
time1[lab5]=' ';
else if((lab5>10)&&(lab5<13))
time1[lab5]=hou[lab5-11];
else if(lab5==13)
time1[lab5]=':';
else if((lab5>13)&&(lab5<16))
time1[lab5]=min[lab5-14];
else if(lab5==16)
time1[lab5]=':';
else if((lab5>16)&&(lab5<19))
time1[lab5]=sec[lab5-17];
}
/*--array devide end!!--*/
textcolor(26);
fputs(ips,fa);
fputc('\t',fa);
fputs(time1,fa);
fputc('\t',fa);
fputs(way,fa);
fputc('\t',fa);
fputs(visit,fa);
fputc('\t',fa);
fputs(filetype,fa);
fputc('\n',fa);
/*
cprintf("%s\r\n",chn);
cprintf(" ip %s,time %s,method %s,visit %s,filetype %s\r\n",ips,time1,way,visit,filetype);
*/
/*empty(chn,p);*/
for(fly=0;fly<p;fly++)
chn[fly]='';
p=0;
ip++;
sleep(0);
}
else
{
chn[p]=ok;
p++;
}
}
printf("\nprogram end!!");
fclose(fa);
fclose(fp);
getch();
}