接收的全部IP数据报个数
由于IP报头错误而被丢弃的输入IP数据报个数
由于目的IP地址无效而导致丢弃的输入IP数据报个数如果方便能不能给一点源程序,以供参考,谢谢各位

解决方案 »

  1.   

    方案一:举个例子,如果你想获取某台网络设备接收的全部IP包数目,你可以通过SNMP协议访问这台设备的MIB库来获取这项数据。其他几项数据也可以通过SNMP来获取。
    方案二:自行写代理程序(用C或C++),把代理安装到你要监控的机器上,代理截取本机接收到的IP数据包(就像sniffer一样),统计分析后把结果发送回管理站。
      

  2.   

    四 做一个自己的sniff 在上一节里,我们已经知道了SNIFF的基本原理是怎么一回事,这一节我们来亲自动手做一个自己的sniff,毕竟,用程序代码来说话比什么都要来得真实,也容易加深理解。  回头想一想我们上面说的原理,我们要做的事情有几件:   1. 把网卡置于混杂模式。                                                            2. 捕获数据包。                                                                 3. 分析数据包。注:下面的源代码取至Chad Renfro的<< Basic Packet-Sniffer Construction from the Ground Up>>一文中
    /************************Tcp_sniff_2.c********************/
    1.#include  
    2.#include  
    3.#include
    4.#include
    5.#include
    6.#include
    7.#include  
    8.#include
    9.#include "headers.h"
      
    #define INTERFACE "eth0"
      
     /*Prototype area*/
      
    10.int Open_Raw_Socket(void); 
    11.int Set_Promisc(char *interface, int sock); 
    12.int main() {  
    13.int sock, bytes_recieved, fromlen;  
    14.char buffer[65535];
    15.struct sockaddr_in from; 
    16.struct ip *ip;
    17.struct tcp *tcp;  
    18.sock = Open_Raw_Socket();
    19. Set_Promisc(INTERFACE, sock);
      
    20. while(1)
    22. {
    23. fromlen = sizeof from;
    24. bytes_recieved = recvfrom(sock, buffer, sizeof buffer, 0, (struct sockaddr *)&from, &fromlen);
    25. printf("\nBytes received ::: %5d\n",bytes_recieved);
    26. printf("Source address ::: %s\n",inet_ntoa(from.sin_addr));
    27. ip = (struct ip *)buffer;
    /*See if this is a TCP packet*/
    28. if(ip->ip_protocol == 6) {
    29. printf("IP header length ::: %d\n",ip->ip_length);
    30. printf("Protocol ::: %d\n",ip->ip_protocol);
    31. tcp = (struct tcp *)(buffer + (4*ip->ip_length));
    32. printf("Source port ::: %d\n",ntohs(tcp->tcp_source_port));
    33. printf("Dest port ::: %d\n",ntohs(tcp->tcp_dest_port));
    34. }
      
    35. }
    36.}
    37.int Open_Raw_Socket() {    
    38. int sock;
    39. if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) {
    /*Then the socket was not created properly and must die*/
    40. perror("The raw socket was not created");
    41. exit(0);
    42. };  
    43. return(sock);  
    44. }
      
    45.int Set_Promisc(char *interface, int sock ) {  
    46. struct ifreq ifr;      
    47. strncpy(ifr.ifr_name, interface,strnlen(interface)+1);
    48. if((ioctl(sock, SIOCGIFFLAGS, &ifr) == -1)) {  
    /*Could not retrieve flags for the interface*/
    49. perror("Could not retrive flags for the interface");
    50. exit(0);
    51. } 
    52. printf("The interface is ::: %s\n", interface);  
    53. perror("Retrieved flags from interface successfully");
    54. ifr.ifr_flags |= IFF_PROMISC;  
    55. if (ioctl (sock, SIOCSIFFLAGS, &ifr) == -1 ) {  
    /*Could not set the flags on the interface */  
    56. perror("Could not set the PROMISC flag:");
    57. exit(0);    
    58. }
    59. printf("Setting interface ::: %s ::: to promisc", interface);
    60. return(0);
    61. }
      

  3.   

    对了,我要的java程序,因为我对java现在还怎么了解,对它里面的函数,类都不熟悉,还没有能力把上面那段翻译成java程序,你能不能给出java程序啊,谢谢了
      

  4.   

    给楼上的,你忘了一个问题--Java是不能进行IP层的操作的,也就是说根本没法去解析IP包,所以sniff类软件肯定是用C或者C++来写的。楼主可要多给点分