These days I was doing a a bit of studies on C++ and Networking,IP and WinSock and found out a method to query *ALL* interfaces and find out the speed, data transfer etc...
The secret lies in the API function GetIfTable in IpHlpApi.dll. It could be put to work in XWidget, ending all the speculations and bug reports of NetMonitorCore not showing any data.
The code was tested to work for modems,bluetooth pan networks,Wi-Fi,LAN,Ethernet,and VPN's. And it works accurately with all of them. With a very little effort it could be put to use in XWidget.
Here is some C++ code that XWidget developers may find useful. (Not for Widget developers)\
Code:
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <vector>
#include <winsock2.h>
//#include <ws2tcpip.h>
#include <Iphlpapi.h>
void UpdateData()
{
DWORD ret, size = 0, c_NumOfTables;
PMIB_IFTABLE ifTable = nullptr;
if ((ret = GetIfTable(ifTable, &size, FALSE)) == ERROR_INSUFFICIENT_BUFFER)
{
ifTable = (PMIB_IFTABLE)malloc(size);
ret = GetIfTable(ifTable, &size, FALSE);
}
if (ret == NO_ERROR)
{
c_NumOfTables = ifTable->dwNumEntries;
wprintf(L"------------------------------\n");
wprintf(L"* NETWORK-INTERFACE: Count=%i\n", c_NumOfTables);
for (size_t i = 0; i < c_NumOfTables; ++i)
{
const WCHAR* type = L"";
switch (ifTable->table[i].dwType)
{
case IF_TYPE_ETHERNET_CSMACD:
type = L"Ethernet";
break;
case IF_TYPE_PPP:
type = L"PPP";
break;
case IF_TYPE_SOFTWARE_LOOPBACK:
type = L"Loopback";
break;
case IF_TYPE_IEEE80211:
type = L"IEEE802.11";
break;
case IF_TYPE_TUNNEL:
type = L"Tunnel";
break;
case IF_TYPE_IEEE1394:
type = L"IEEE1394";
break;
default:
type = L"Other";
break;
}
wprintf(L"%i: %.*S\n", (int)i + 1, ifTable->table[i].dwDescrLen, (char*)ifTable->table[i].bDescr);
wprintf(L" Type=%s(%i)\n", type, ifTable->table[i].dwType);
wprintf(L" Bytes sent: %d Bytes Received %d\n",ifTable->table[i].dwInOctets,ifTable->table[i].dwOutOctets);
}
wprintf(L"------------------------------\n");
}
}
int _tmain(int argc, _TCHAR* argv[])
{
printf("Initializing netmon\n");
while(true) {
UpdateData();
Sleep(1000);
}
}
Compiles with absolutely any compiler. I used Visual Studio 2012 though.
Another long standing request is to release an API to allow independent developers to write cores in languages like C++. The popular Rainmeter holds this feature since long. And, it's rather easy to add such a feature. Except for the designer integration part, but still holds a solution!
