当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

一个分析日志的程序

    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/access1.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++;
                              }
                          }
                      }
 

共3页 首页 上一页 1 2 3 下一页 尾页 跳转到
相关内容
赞助商链接