www.pudn.com > SearFTP.rar > SearchTFTP.cpp


/***************************************************************| 
                        Author:   JIURL 
						Email:    jiurl@mail.china.com 
						Homepage: http://jiurl.yeah.net 
/***************************************************************/ 
#include  
#include  
#include  
#include  
 
#pragma comment (lib,"ws2_32") 
 
unsigned int naddr; 
unsigned int naddrend; 
 
#define TFTP_RRQ   1 
#define TFTP_WRQ   2 
#define TFTP_DATA  3 
#define TFTP_ACK   4 
#define TFTP_ERROR 5 
 
void searcher(); 
 
void SearchTFTP(); 
 
void main() 
{ 
	WSADATA wsaData; 
	int nRet; 
 
	nRet = WSAStartup(0x0202, &wsaData); 
	if (nRet != 0) 
	{ 
		printf("WSAStartup() failed with error %d\n", nRet); 
		return; 
	} 
 
	SearchTFTP(); 
	 
	WSACleanup(); 
} 
 
void SearchTFTP() 
{ 
	char BeginIP[20]; 
	char EndIP[20]; 
 
	printf("Begin IP : "); 
	scanf("%s",BeginIP); 
	printf("End IP : "); 
	scanf("%s",EndIP); 
		 
	int maxnthread; 
 
	printf("Ïß³ÌÊý : "); 
	scanf("%d",&maxnthread); 
 
	printf("\nFrom %s To %s\n\n\n",BeginIP,EndIP); 
 
	naddr=inet_addr(BeginIP); 
	naddr=ntohl(naddr); 
	naddrend=inet_addr(EndIP); 
	naddrend=ntohl(naddrend); 
 
	DWORD threadID[200]; 
	int nthread; 
 
	DWORD dwStart = GetTickCount();//del 
 
	for(nthread=0;nthread1000)// 
		printf("Use %d seconds \n",time/1000 );//del 
	else// 
		printf("Use %d milliseconds \n",time );// 
 
	getch(); 
 
} 
 
void searcher() 
{ 
	SOCKET	theSocket; 
 
	theSocket = socket(AF_INET,			// Address family 
					   SOCK_DGRAM,		// Socket type 
					   IPPROTO_UDP);	// Protocol 
	if (theSocket == INVALID_SOCKET) 
	{ 
		printf("socket() error\n"); 
		return ; 
	} 
 
	SOCKADDR_IN saServer; 
 
	saServer.sin_family = AF_INET;										 
	saServer.sin_port = htons(69); 
 
	int BufLen; 
	char SendBuf[516]; 
	char RecvBuf[516]; 
 
	SendBuf[0]=0; 
	SendBuf[1]=TFTP_RRQ; 
	 
	char* cp=SendBuf+2; 
 
	strcpy(cp,"//etc//password"); 
	cp += strlen("//etc//password"); 
	cp++; 
	strcpy(cp, "octet"); 
	cp += strlen("octet"); 
	cp++; 
	BufLen = cp-SendBuf; 
 
	int timeout; 
	timeout= 1000; 
 
	unsigned int thnaddr; 
	unsigned int thnaddrend; 
	thnaddr=naddr++; 
	thnaddrend=naddrend; 
 
	int nRet; 
 
	while(thnaddr\n"); 
			else printf("\n"); 
		} 
 
		thnaddr=naddr++; 
	} 
}