Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef UNICODE
- #define UNICODE
- #endif
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <Windows.h>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <iphlpapi.h>
- #include <objbase.h>
- #include <wtypes.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- // Need to link with Iphlpapi.lib
- #pragma comment(lib, "iphlpapi.lib")
- // Need to link with Ole32.lib to print GUID
- #pragma comment(lib, "ole32.lib")
- // Print some parameters from the MIB_IF_ROW2 structure
- long long int PrintIfEntry2(PMIB_IF_ROW2 pIfRow)
- {
- std::cout << pIfRow->InOctets << "\n";
- return pIfRow->InOctets;
- //wprintf(L"\tIn Octets:\t %I64u\n", pIfRow->InOctets);
- //wprintf(L"\tOut Octets:\t %I64u\n", pIfRow->OutOctets);
- }
- long long test(WCHAR** args) {
- std::cout << "running:" << args << ":End" << "\n";
- // Declare and initialize variables
- ULONG retVal1 = 0;
- ULONG retVal2 = 0;
- ULONG ifIndex1;
- ULONG ifIndex2;
- MIB_IF_ROW2 ifRow1;
- MIB_IF_ROW2 ifRow2;
- // Make sure the ifRow is zeroed out
- SecureZeroMemory((PVOID)&ifRow1, sizeof(MIB_IF_ROW2));
- // Zero out the MIB_IF_ROW2 struct
- ifIndex1 = _wtoi(args);
- ifRow1.InterfaceIndex = ifIndex1;
- retVal1 = GetIfEntry2(&ifRow1);
- long long oct1 = PrintIfEntry2(&ifRow1);
- Sleep(1000);
- // Make sure the ifRow is zeroed out
- SecureZeroMemory((PVOID)&ifRow2, sizeof(MIB_IF_ROW2));
- ifIndex2 = _wtoi(args);
- ifRow2.InterfaceIndex = ifIndex2;
- retVal2 = GetIfEntry2(&ifRow2);
- long long oct2 = PrintIfEntry2(&ifRow2);
- long long rise = (oct2 - oct1) * 8;
- //rise = rise / 1000 / 1000;
- return rise;
- }
- int __cdecl wmain(int argc, WCHAR** argv)
- {
- // Validate the parameters
- if (argc < 2) {
- wprintf(L"usage: %s <InterfaceIndex>\n", argv[0]);
- wprintf(L" Gets the Interface Entry for an interface Index,\n");
- wprintf(L"Example to get the interface at interface index=6\n");
- wprintf(L" %s 6\n", argv[0]);
- exit(1);
- }
- std::cout << test((WCHAR**)argv[1]);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement