http://gamedev.uhome.net/GUNiffer.zip
2000下使用,shotgun写的

解决方案 »

  1.   

    到http://netgroutp-serve.polito.it下载ndis开发包,那里面提供了.lib and .h文件和例子代码。看了就知道了。
    注意:不要做坏事喔!
      

  2.   

    TO dutsf(阿石) :我怎么上不了http://netgroutp-serve.polito.it
      

  3.   

       to milson(老疯子) :
       你有好东东的话就拿出来给大家分享嘛! 大家说是不是?
       哦,对了,http://netgroutp-serve.polito.it 我也上不了!
      

  4.   

    win2000 ddk 中有源码,有许多商业软件的捕获程序就使用它,除了改一些公司名字外,其他一点没变。
      

  5.   

    To: sunwzd()
    我认为要使丢包率降低,至少应该是多服务器模式,如果是在lunux上,呵呵,那就更有文章可作了。事实上我就是那么做的。至于程序,sorry,我不能给上,请谅解。
      

  6.   

    To: sunwzd()
    我认为要使丢包率降低,至少应该是多服务器模式,如果是在linux上,呵呵,那就更有文章可作了。事实上我就是那么做的。至于程序,sorry,我不能给上,请谅解[email protected] :)
      

  7.   

    我师兄的linux下的代码:
    //sniffer.c  Power by flying#include <sys/socket.h>
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <netinet/ether.h>
    #include <netinet/tcp.h>
    #include <netinet/ip.h>
    #include <linux/if.h>
    #include <stdio.h>
    #include <arpa/inet.h>
    #include <netinet/in.h>
    #include <bits/sockaddr.h>
    #include <netdb.h>
    #include <string.h>
    /*****************Define global marocs************************/
    #define     SIG_EXIT        23
    #define     MAXSIZE         8000
    #define     SCKERROR        -1
    #define     GETIOSTERROR    -2
    #define     SETIOSTERROR    -3
    #define     TCPFIN          "[==FIN==]"
    #define     TCPSYN          "[==SYN==]"
    #define     TCPRST          "[==RST==]"
    #define     TCPACK          "[==ACK==]"//Buffer that store data from socket
    typedef struct DataPacket {
        struct ethhdr eth;
        struct iphdr ip;
        struct tcphdr tcp;
        char DataBuffer[MAXSIZE];
    } DataBuf;//Global values
    DataBuf EthDataPck;
    struct iphdr * ip;
    struct tcphdr * tcp;
    int SnifferSocket;
    //log files
    FILE * pid_log;
    FILE * http_log;
    FILE * pop_log;
    FILE * smtp_log;
    FILE * ftp_log;struct ifreq old_status;
    int IsWriteData;
    int IsWriteHead;//Functions here
    int InitSocket(char *);
    int ResetDev(void);
    void DoSnif(int);
    void DoRecordBuf(void);
    int BeginSniffer(void);
    void ShowUsageMsg(void);
    void StartUp(void);
    void ShutDown(void);
    void WritePidToLog(int);
    int ReadPidFromLog(void);
    void DoExit(void);
    void OpenLogFiles(void);
    void CloseLogFiles(void);
    void WriteDataToFile(FILE *);
    void WriteHeadToFile(FILE *);
    char * GetHostName(unsigned long int);/***********Write information head to correct log file************/
    void WriteHeadToFile(FILE * f) {
        if (IsWriteHead == 0)
            return;
        IsWriteHead = 0;
        fprintf(f,"From : %s\t",GetHostName(ip->saddr));
        fprintf(f,"To : %s\nPort : [%d]\n",GetHostName(ip->daddr),
    ntohs(tcp->dest));
    }
    /***********Write information body to correct log file************/
    void WriteDataToFile(FILE * f) {
        char * msg;
        int loop,len;
        if (IsWriteData == 0) {
            return;
        }
        IsWriteData = 0;
        msg = EthDataPck.DataBuffer - 2;
        if (ntohs(tcp->dest) == 25) {
            len = htons(ip->tot_len)-sizeof(EthDataPck.
    ip)-sizeof(EthDataPck.tcp);
        } else if (ntohs(tcp->dest) == 80) {
            len = strlen(msg);
        } else if (ntohs(tcp->dest) == 110) {
            len = htons(ip->tot_len)-sizeof(EthDataPck.
    ip)-sizeof(EthDataPck.tcp);
        } else if (ntohs(tcp->dest) == 21) {
            len = htons(ip->tot_len)-sizeof(EthDataPck.
    ip)-sizeof(EthDataPck.tcp);
        } else {
            return;
        }
        for (loop = 0; loop < len; loop++) {
            if (msg[loop] == 13) {
                fprintf(f,"\n");
            } else {
                fprintf(f,"%c",msg[loop]);
            }
        }
        fprintf(f,"\n");
    }//Init socket and device status
    int InitSocket(char * dev) {
        struct ifreq ifr;
        int s;
        int sck;
        sck = socket(AF_INET,SOCK_PACKET,htons(0x800));
        if (sck < 0) {
            return SCKERROR;
        }
        strcpy(ifr.ifr_name,dev);
        s = ioctl(sck,SIOCGIFFLAGS,&ifr);
        if (s < 0) {
            close(sck);
            return GETIOSTERROR;
        }
        //remember what status it used to be
        memcpy(&old_status,&ifr,sizeof(struct ifreq));
        ifr.ifr_flags |= IFF_PROMISC;
        s = ioctl(sck,SIOCSIFFLAGS,&ifr);
     if (s < 0) {
     close(sck);
     return SETIOSTERROR;
     }
     return sck;
    }/**************Begin to get data from device******************/
    void DoSnif(int sck) {
        int datasize;
        while (1) {
            datasize = read(sck,(struct etherpacket *)&EthDataPck,
    sizeof(DataBuf));
            if (datasize > 1) {
                DoRecordBuf();
        }
     }
    }/************Do with data and log correct 
    information*****************/
    void DoRecordBuf() {
        int tcpport;
        FILE * f;
        struct in_addr inaddr;
        char strIP[11];
        if (ip->protocol != 6)
            return;
        tcpport = ntohs(tcp->dest);
        switch (tcpport) {
        case 110:
            f = pop_log;
            break;
        case 25:
            f = smtp_log;
            break;
        case 80:
        f = http_log;
         break;
        case 21:
            f = ftp_log;
            break;
        default:
            return;
            break;
        }
        if (tcp->fin == 1) {
            fprintf(f,"Status : %s\n",TCPFIN);
            IsWriteData = 0;
            IsWriteHead = 1;
        } else if (tcp->fin == 0) {
            if (tcp->rst == 1) {
                IsWriteHead = 1;
                if (tcp->syn == 0) {
                    fprintf(f,"Status : %s\n",TCPRST);
                    IsWriteData = 0;
                } else {
                    if (tcp->ack == 0) {
                        fprintf(f,"Status : %s\t%s\n",TCPRST,TCPSYN);
                        IsWriteData = 1;
                    } else {
                        fprintf(f,"Status : %s\t%s\t%s\n",TCPRST,TCPSYN,
    TCPACK);
                        IsWriteData = 0;
                    }
                }
            } else if (tcp->rst == 0) {
                if (tcp->syn == 1) {
                    IsWriteHead = 1;
                    if (tcp->ack == 0) {
                        fprintf(f,"Status : %s\n",TCPSYN);
                        IsWriteData = 1;
                    } else {
                        fprintf(f,"Status : %s\t%s\n",TCPSYN,TCPACK);
                        IsWriteData = 0;
                    }
                }
            }
        }
        inaddr.s_addr = ip->saddr;
        strncpy(strIP,inet_ntoa(inaddr),10);
        strIP[10] = '\0';
        if (!strcmp(strIP,"192.168.1.")) {
            if (IsWriteHead == 1) {
                WriteHeadToFile(f);
            }
            if (IsWriteData == 1) {
                WriteDataToFile(f);
            }
        }
    }/****************Tell others how to use this 
    software******************/
    void ShowUsageMsg() {
        printf("FSnif usage:{start|stop}\n");
        exit(0);
    }/****************Begin to do with sniffer************************/
    int BeginSniffer() {
        int pid;
        setpgrp();
        pid = getpid();
        WritePidToLog(pid);
        signal(SIG_EXIT,DoExit);
        ip = (struct iphdr *)(((unsigned long)&EthDataPck.ip)-2);
        tcp = (struct tcphdr *)(((unsigned long)&EthDataPck.tcp)-2);
        IsWriteData = 0;
        IsWriteHead = 0;
        OpenLogFiles();
        SnifferSocket = InitSocket("eth0");
        DoSnif(SnifferSocket);
        return 0;
    }/*************If the user decide to start it,do this**************/
    void StartUp() {
        int pid;
        pid = fork();
        switch (pid) {
        case 0:
            BeginSniffer();
            break;
        case -1:
            printf("Cannot fork,please retry!\n");
            exit(0);
            break;
        default:
            exit(0);
            break;
        }
    }/**************Save the process ID to file************/
    void WritePidToLog(int pid) {
        pid_log = fopen("pid/pid","w");
        fprintf(pid_log,"%d",pid);
        fclose(pid_log);
    }
    int ReadPidFromLog() {
        int pid,log,len;
        char chrpid[10];
        log = open("pid/pid",O_RDONLY);
        len = read(log,chrpid,10);
        chrpid[len] = 0;
        pid = atoi(chrpid);
        close(pid_log);
        return pid;
    }/*****************Do this so that the sniffer can stop 
    working********/
    void ShutDown() {
        int pid;
        pid = ReadPidFromLog();
        kill(pid,SIG_EXIT);
    }
    void DoExit() {
        while (!(ResetDev() == 0));
        close(SnifferSocket);
        CloseLogFiles();
        exit(0);
    }
    int ResetDev() {
        int s;
        s = ioctl(SnifferSocket,SIOCSIFFLAGS,&old_status);
        if (s < 0)
            return (-1);
    }
    void OpenLogFiles() {
        http_log = fopen("log/http.log","at");
        smtp_log = fopen("log/smtp.log","at");
        pop_log = fopen("log/pop.log","at");
        ftp_log = fopen("log/ftp.log","at");
    }
    void CloseLogFiles() {
        fclose(http_log);
        fclose(smtp_log);
        fclose(pop_log);
        fclose(ftp_log);
    }
    char * GetHostName(unsigned long int in) {
        static char hostname[1024];
        struct in_addr i;
        struct hostent * remotehost;
        i.s_addr=in;
        remotehost = gethostbyaddr((char *)&i, sizeof(struct in_addr),
    AF_INET);
        if(remotehost == NULL)
            strcpy(hostname, inet_ntoa(i));
        else
            strcpy(hostname, remotehost->h_name);
        return hostname;
    }
    int main(int argc,char ** argv) {
        switch (argc) {
        case 1:
            ShowUsageMsg();
            break;
        case 2:
            if (strcmp(argv[1],"start") == 0) {
                StartUp();
            } else if (strcmp(argv[1],"stop") == 0) {
                ShutDown();
            } else {
                ShowUsageMsg();
            }
            break;
        default:
            ShowUsageMsg();
            break;
        }
    }
      

  8.   

      我把在http://gamedev.uhome.net/GUNiffer.zip上的这个程序修改了一下(以前时命令行形式的,现在支持界面、多线程了),发现很好用,就上传到www.inetsoft.8u8.com上跟大家分享。注意:程序中还有两个小问题,1:在sock数据接收错误的时候把exit换成你自己的错误信息提示函数;2:在tcp解析程序中有一个漏洞,当数据太长的时候(最长可以达到65535,而我定义的一行是1024,所以需要分批显示,当然这是在启用/p参数时才需要这样的。我尽快把新版本传上去。 对了,那个程序要在win2000下才可以 !
      

  9.   

      否则会报告错误errorcode = 10022(wsa初始化错误)