hi every one i'm pretty new to programing so i want ur help.

i want to create a program that counts the number of the downloaded bytes form all ur activity over the internet. that is when ever the internet connection is established the program starts to count the bytes that the user download by several activities for example web surfing or using the voice service in yahoo messenger.

just give me hints. i don't know how do c++ know that the internet is on. besides how do c++ integrates to the main stream of your internet connection to know how many bytes are downloaded.


i just need hints, thank you very much...:)

First of all: Why? This sounds like you're making somesort of malware/spyware and that's against the rules.

>>i don't know how do c++ know that the internet is on

:?:

Edited 6 Years Ago by Nick Evan: n/a

Network status information can be gathered from the network adapters on the machine. Here is a sample that does it on Windows to give you ideas.

// Compiled and run with Visual C++ 2010
#include <cstdlib>
#include <iostream>
#include <vector>
#include <windows.h>
#include <iphlpapi.h>

#pragma comment(lib, "IPHLPAPI.lib")

int main()
{
    DWORD size = sizeof MIB_IFTABLE;
    std::vector<BYTE> tab(size);

    // Use Microsoft's akward method to get the right size and populate the IF table
    if (GetIfTable((PMIB_IFTABLE)&tab[0], &size, FALSE) == ERROR_INSUFFICIENT_BUFFER) {
        tab.resize(size);

        if (GetIfTable((PMIB_IFTABLE)&tab[0], &size, FALSE) != NO_ERROR) {
            std::cerr << "Error retrieving IF table\n";
            std::exit(EXIT_FAILURE);
        }
    }

    // The table is allocated and populated now
    PMIB_IFTABLE ptab = (PMIB_IFTABLE)&tab[0];

    std::cout.imbue(std::locale("")); // Add commas to numeric output
    
    for (DWORD i = 0; i < ptab->dwNumEntries; i++) {
        PMIB_IFROW row = &ptab->table[i];

        if (row->dwType == IF_TYPE_ETHERNET_CSMACD &&
            (row->dwOperStatus == IF_OPER_STATUS_OPERATIONAL ||
             row->dwOperStatus == IF_OPER_STATUS_CONNECTED))
        {
            if (row->dwInOctets > 0 || row->dwOutOctets > 0) {
                // Display network interfaces with activity
                std::cout << row->bDescr << '\n'
                          << "Bytes sent:     " << row->dwInOctets << '\n'
                          << "Bytes received: " << row->dwOutOctets << '\n';
            }
        }
    }
}

First of all: Why? This sounds like you're making somesort of malware/spyware and that's against the rules.

There would be no point for malware to do something like that..

thank u mr. Nick Evan,
and don't worry i just wanted to create a program of my own that keeps a record of my internet usage because the company i subscribed for is limiting me activity. i'm allowed maximum for 7 gigabytes :) per month.
------

i meant by ">>i don't know how do c++ know that the internet is on"
that my program will keep waiting until the internet connection established then it will call a function that starts to count the bytes. i was assuming.

thank you for your help and i will work on the program

This article has been dead for over six months. Start a new discussion instead.