最近在研究流量监控,好不容易找到了这几个东东,GetIfTable(),GetIfEntry(),结构体MIB_IFROW,成员dwInOctets,dwOutOctets,dwSpeed,但是不知道具体怎么用,因为用简单的程序写出来,得到的数值永远是个很大的值,而且不会有改变,我知道dwInOctets,dwOutOctets这两个是累积值,而dwSpeed应该是瞬时值,可惜程序里面不知道出了什么问题,
#include "iostream" #include "windows.h" #include <iphlpapi.h> #include <process.h> #pragma comment(lib, "iphlpapi.lib") using namespace std; int main() { int a; MIB_IFTABLE* ifTable = new MIB_IFTABLE[6]; MIB_IFROW sum; unsigned long len=sizeof(ifTable); GetIfTable(ifTable,&len,TRUE); sum.dwIndex=ifTable->table[6].dwIndex; a=GetIfEntry(&sum); while(TRUE) { cout<<a<<" "<<sum.dwSpeed<<endl; system("CLS"); } return 0; }