How to write the simplest port scanner:
One: New Win32 console application supporting MFC; 2: Add two global variables in scanport.cpp: int i; csocket suckclient; add thread process definition: DWORD WINAPI Scanports (LPVOID);
INT _TMAIN (int Argc, tchar * argv [], tchar * envp [] code is as follows:
INT _TMAIN (int Argc, tchar * argv [], tchar * envp []) {int nretcode = 0; // initialize mfc and print and error on failure if (! AFXWININIT (: getModuleHandle (NULL), NULL,: Getcommandline (), 0) {// Todo: Change Error Code To Suit Your Needs Cerr <<_T ("Fatal Error: MFC Initialization Faled") << ENDL; NRETCODE = 1;} else {:: setConsoletitle ("scan Ports - Written By CodeWorrior ");
//// / scanned host can be changed to user input /// // Todo: code your application's behavior here. AfXSocketinit (null);
For (i = 1; i <= 10; i ) {handle hthread; DWORD DWTHREADID; File: // Cout << i << end1; hthread = Createthread (Null, 0, Scanports, (LPVOID) i, 0, & DWTHREADID ); Sleep (1000) ;: WaitForsingleObject (hthread, 200); closehandle (hthread);}} cout << endl; return nretcode;}