Guest User

Untitled

a guest
Jul 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <winsock2.h>
  3. #include <ws2tcpip.h>
  4. #pragma comment(lib, "ws2_32.lib")
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. // Logo
  10. cout << " ******************************************* " << endl;
  11. cout << " ************* KiAnalyzer v0.1 ************* " << endl;
  12. cout << " ******************************************* " << endl;
  13. cout << "\n";
  14.  
  15. // Status
  16. cout << "*** Status ***" << endl;
  17.  
  18. // Startup
  19. WSADATA wdata;
  20. int iStart = WSAStartup(MAKEWORD(2,2), &wdata);
  21. if( iStart == SOCKET_ERROR )
  22. {
  23. cout << "Startup Fail" << endl;
  24. }
  25. else {
  26. cout << "Startup Success" << endl;
  27. }
  28.  
  29. // Socket
  30. SOCKET sConnect = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  31. if( sConnect == SOCKET_ERROR )
  32. {
  33. cout << "Socket Fail" << endl;
  34. WSACleanup();
  35. }
  36. else {
  37. cout << "Socket Success" << endl;
  38. }
  39.  
  40. // Info
  41. SOCKADDR_IN info;
  42. info.sin_family = AF_INET;
  43. info.sin_addr.s_addr = inet_addr("127.0.0.1");
  44. info.sin_port = htons(22580);
  45.  
  46. // Connect
  47. int iConn = connect(sConnect, (SOCKADDR *)&info, sizeof(info));
  48. if( iConn == SOCKET_ERROR )
  49. {
  50. cout << "Connect Fail" << endl;
  51. WSACleanup();
  52. closesocket(sConnect);
  53. }
  54. else {
  55. cout << "Connect Success" << endl;
  56. }
  57.  
  58. // Print
  59. cout << "\n" << "*** Packets Recieved ***" << endl;
  60.  
  61. // Recieve
  62. char cRecv[8192];
  63. int iRecieve;
  64.  
  65. while(true)
  66. {
  67. iRecieve = recv(sConnect, cRecv, sizeof(cRecv), 0);
  68. for(int i = 0; i < iRecieve; i++)
  69. {
  70. printf("%.2X", cRecv[i]);
  71. }
  72. printf("\n\n");
  73. }
  74.  
  75. if( iRecieve == SOCKET_ERROR )
  76. {
  77. cout << "Recieve Fail" << endl;
  78. }
  79. else {
  80. cout << "\n" << cRecv << endl;
  81. }
  82.  
  83. WSACleanup();
  84. closesocket(sConnect);
  85.  
  86. cin.get();
  87. return 0;
  88. }
Add Comment
Please, Sign In to add comment