README.md

December 5, 2022 ยท View on GitHub

Internet usage computation program

Description

An application to check current Internet usage

More Info

Using the 'netstat -e' dos command within a C program to compute the internet usage in megabyte :-)

Submitted On
ByDebanjan Chanda
LevelIntermediate
User Rating4.0 (8 globes from 2 users)
CompatibilityC, C++ (general), Microsoft Visual C++, Borland C++
CategoryInternet/ Browsers/ HTML
WorldC / C++
Archive File

API Declarations

<stdio.h> & <stdlib.h>

Source Code

//////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
//////////////////////////////////////////////////
int main(void)
{
	unsigned long bytes_sent, bytes_received; /*You can use unsigned long long */
	FILE *temp_file;
	system("netstat -e > usage.in");  /* Sending Output to a temporary File */
	temp_file = fopen("usage.in","r");
	fscanf(temp_file,"%*s%*s%*s%*s%*s%llu%llu",&bytes_received, &bytes_sent);
	printf("%s","Your net usage statistics:(This Session)\n");
	printf("%s","------------------------------------------\n\n");
	printf("%s%8.3f MB\n","Sent:   ", (((double)bytes_sent) / ((double)(1024 * 1024))));
	printf("%s%8.3f MB\n","Received: ", (((double)bytes_received) / ((double)(1024 * 1024))));
	printf("%s%8.3f MB\n\n","Total:  ", (((double)(bytes_sent + bytes_received)) / ((double)(1024 * 1024))));
  system("pause");
  fclose(temp_file);
  system("del usage.in");  /* Deleting the temporary File */
	return 0;
}
//////////////////////////////////////////////////