Telnet.cpp
上传用户:aphszp
上传日期:2007-01-09
资源大小:42k
文件大小:2k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <winsock.h>
  4. #include <process.h>
  5. #include "SocketRx.h"
  6. #include "SocketDx.h"
  7. #include "SocketTx.h"
  8. #include <conio.h>
  9. #include "Telnet.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. CWinApp theApp;
  16. using namespace std;
  17. HANDLE stdin1;
  18. HANDLE hHeap1;
  19. HANDLE stdout1;
  20. HANDLE stderr1;
  21. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  22. {
  23. int nRet;
  24. WSADATA wd;
  25. int nPort;
  26. char strIP[256];
  27. char strTitle[256];
  28. SOCKET hSocket;
  29. HANDLE hThread[2];
  30. nRet = AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
  31. if ( nRet == FALSE )
  32. {
  33. printf("nAfxWinInit Fail..............!n");
  34. return 0;
  35. }
  36. nPort = IPPORT_TELNET;
  37. SetConsoleTitle("Try To connect...");
  38.    WSAStartup(0x0101,&wd);
  39.     
  40. stdin1 = GetStdHandle(STD_INPUT_HANDLE);
  41. stdout1 = GetStdHandle(STD_OUTPUT_HANDLE);
  42. stderr1 = GetStdHandle(STD_ERROR_HANDLE);
  43. hHeap1 = GetProcessHeap();
  44. SetConsoleMode(stdin1,ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
  45. printf("nPlease Enter IP/Domain.........:");
  46. scanf("%s",strIP);
  47. if ( strlen(strIP) < 3 ) { printf("nBad IP/Domainn"); getch(); return 0; }
  48. printf("nPort...........%d :",nPort);
  49. CSocketDx SocketDx(strIP,nPort);
  50. hSocket = SocketDx.TelnetConnect();
  51. if ( hSocket == NULL ) { printf("nUnable To Connectn");getche(); return 0; }
  52. CSocketRx SocketRx(hSocket,hThread[0]); 
  53. CSocketTx SocketTx(hSocket,hThread[1]);
  54. wsprintf(strTitle,"Connecting to %s:%d",strIP,nPort);
  55. SetConsoleTitle(strTitle);
  56. WaitForMultipleObjects(2,hThread,FALSE,INFINITE);
  57. return 0;
  58. }