들어가기
MIB_IFTABLE *pTable=NULL;
DWORD dwAdapters=0;
DWORD dwTotalIn=0,dwTotalOut=0;
DWORD dwOldTotalIn=0,dwOldTotalOut=0;
double trafficIn = 0.0, trafficOut = 0.0;
bool isTrafficFirst = true;
ULONG uRetCode = 0;
while(true) {
dwAdapters = 0;
dwTotalIn=0,dwTotalOut=0;
uRetCode=GetIfTable(pTable,&dwAdapters,FALSE);
if (uRetCode == 122) {
pTable=new MIB_IFTABLE[dwAdapters];
GetIfTable(pTable,&dwAdapters,FALSE);
for (UINT i=0; i < pTable->dwNumEntries;i++) {
MIB_IFROW Row=pTable->table[i];
dwTotalIn+=Row.dwInOctets;
dwTotalOut+=Row.dwOutOctets;
}
delete []pTable;
pTable = NULL;
if( isTrafficFirst ) {
isTrafficFirst = false;
dwOldTotalIn = dwTotalIn;
dwOldTotalOut = dwTotalOut;
} else {
trafficIn = (dwTotalIn - dwOldTotalIn) / 2;
trafficOut = (dwTotalOut - dwOldTotalOut) / 2;
dwOldTotalIn = dwTotalIn;
dwOldTotalOut = dwTotalOut;
}
}
printf("Bytes Received %.2f kbyte/s, Sent %.2f kbyte/s\n",trafficIn/1024.0, trafficOut/1024.0);
Sleep(2000);
}
트래픽 측정
반응형
'3.구현 > VC++' 카테고리의 다른 글
메모리릭(Memory leak) 관련 (0) | 2012.08.14 |
---|---|
도스 프롬프트에서 명령어 옵션 처리 (0) | 2012.08.14 |
[에러]LNK1241 Linker Tools Error (0) | 2012.08.14 |
[버그,error] UuidToStringW use RPC_WSTR (0) | 2012.08.14 |
[명령어] dumpbin (0) | 2012.08.14 |