Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #ifndef WIN32_LEAN_AND_MEAN
  6. #define WIN32_LEAN_AND_MEAN
  7. #endif
  8.  
  9. #include <Windows.h>
  10.  
  11. #include <winsock2.h>
  12. #include <ws2tcpip.h>
  13. #include <iphlpapi.h>
  14.  
  15. #include <objbase.h>
  16. #include <wtypes.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <iostream>
  20.  
  21. // Need to link with Iphlpapi.lib
  22. #pragma comment(lib, "iphlpapi.lib")
  23.  
  24. // Need to link with Ole32.lib to print GUID
  25. #pragma comment(lib, "ole32.lib")
  26.  
  27.  
  28. // Print some parameters from the MIB_IF_ROW2 structure
  29. long long int PrintIfEntry2(PMIB_IF_ROW2 pIfRow)
  30. {
  31.  
  32. std::cout << pIfRow->InOctets << "\n";
  33.  
  34. return pIfRow->InOctets;
  35.  
  36. //wprintf(L"\tIn Octets:\t %I64u\n", pIfRow->InOctets);
  37. //wprintf(L"\tOut Octets:\t %I64u\n", pIfRow->OutOctets);
  38.  
  39. }
  40.  
  41. long long test(WCHAR** args) {
  42. std::cout << "running:" << args << ":End" << "\n";
  43.  
  44. // Declare and initialize variables
  45.  
  46. ULONG retVal1 = 0;
  47. ULONG retVal2 = 0;
  48. ULONG ifIndex1;
  49. ULONG ifIndex2;
  50.  
  51. MIB_IF_ROW2 ifRow1;
  52. MIB_IF_ROW2 ifRow2;
  53.  
  54. // Make sure the ifRow is zeroed out
  55. SecureZeroMemory((PVOID)&ifRow1, sizeof(MIB_IF_ROW2));
  56.  
  57. // Zero out the MIB_IF_ROW2 struct
  58.  
  59. ifIndex1 = _wtoi(args);
  60.  
  61. ifRow1.InterfaceIndex = ifIndex1;
  62.  
  63. retVal1 = GetIfEntry2(&ifRow1);
  64.  
  65. long long oct1 = PrintIfEntry2(&ifRow1);
  66.  
  67.  
  68. Sleep(1000);
  69.  
  70. // Make sure the ifRow is zeroed out
  71. SecureZeroMemory((PVOID)&ifRow2, sizeof(MIB_IF_ROW2));
  72.  
  73. ifIndex2 = _wtoi(args);
  74.  
  75. ifRow2.InterfaceIndex = ifIndex2;
  76.  
  77. retVal2 = GetIfEntry2(&ifRow2);
  78.  
  79. long long oct2 = PrintIfEntry2(&ifRow2);
  80.  
  81. long long rise = (oct2 - oct1) * 8;
  82.  
  83. //rise = rise / 1000 / 1000;
  84.  
  85. return rise;
  86.  
  87. }
  88.  
  89. int __cdecl wmain(int argc, WCHAR** argv)
  90. {
  91.  
  92. // Validate the parameters
  93. if (argc < 2) {
  94. wprintf(L"usage: %s <InterfaceIndex>\n", argv[0]);
  95. wprintf(L" Gets the Interface Entry for an interface Index,\n");
  96. wprintf(L"Example to get the interface at interface index=6\n");
  97. wprintf(L" %s 6\n", argv[0]);
  98. exit(1);
  99. }
  100.  
  101. std::cout << test((WCHAR**)argv[1]);
  102.  
  103. exit(0);
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement