Solved

Wireless Network trafic meter

Posted on 2011-02-14
3
495 Views
Last Modified: 2013-12-27
I am looking for a free application for windows CE, that it will be meter at KBytes the Wireless trafic of PDA.

Best Regards
0
Comment
Question by:DareDevilE12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 34889986
Hello

some time ago I wrote something to log the data using MIB adapters info. Its written in C++ for windows mobile and hardcoded to only log data for the adapter named "Cellular Line". To get the information about the WLAN adapter, you have to replace "Celleular Line" with the name of the adapter you want to watch:

see attached file

Are you able to use that?

regards

Josef
// AdapterMIBinfo.cpp : Defines the entry point for the application.
//


#include "stdafx.h"
#include "winsock2.h"
#pragma comment (lib, "ws2.lib")

#include "Iphlpapi.h"
#pragma comment (lib, "Iphlpapi.lib")

#include "log2file.h"

TCHAR logname[] = L"traffic.log.txt";
UINT mTimer1 = 0;
TCHAR *szFlagFile = L"\\Windows\\_stop_traffic_log.flag";
DWORD iTime = 30;

void add2log(TCHAR *txt)
{
	Add2Log(txt, false);
}

//use dumpType = 1 for csv dumps of Cellular Line only
int dumpMIBinfos(int dumpType=0)
{
	TCHAR str[2048]=L"";
	// Interface name enumeration
	IP_INTERFACE_INFO *pIpInterface = NULL;
	DWORD dwInterfaceSize = 0;

	// Find out the size of the interface table
	if(GetInterfaceInfo(NULL, &dwInterfaceSize) != ERROR_INSUFFICIENT_BUFFER)
	   return FALSE;

	pIpInterface = (IP_INTERFACE_INFO *)LocalAlloc(LPTR, dwInterfaceSize);
	if(!pIpInterface)
	   return FALSE;

	if(GetInterfaceInfo(pIpInterface, &dwInterfaceSize) != NO_ERROR) {
	   LocalFree(pIpInterface);
	   return FALSE;
	}

	// Walk through the available interfaces
	TCHAR tchInterfaceBuffer[256] = TEXT("\0");
	TCHAR tchStr[1024] = L"\0";
	char   chStr[1024] = "\0";
	for(int nInterface = 0; nInterface < pIpInterface->NumAdapters; nInterface++) 
	{
	   DEBUGMSG(true, (L"--------------------------------------------------------\n"));
		if (dumpType==0)
			add2log(L"--------------------------------------------------------\n");
	   IP_ADAPTER_INDEX_MAP *pIpAdapterMapEntry = NULL;

	   pIpAdapterMapEntry = (IP_ADAPTER_INDEX_MAP *)&pIpInterface->Adapter[nInterface];
	   wsprintf(tchInterfaceBuffer, TEXT("Interface Name: %s\nInterface Index: %d"),pIpAdapterMapEntry->Name, pIpAdapterMapEntry->Index);
	   DEBUGMSG(true, (L"%s\n",tchInterfaceBuffer));
		if (dumpType==0)
			add2log(tchInterfaceBuffer);

		//query the MIB table
	    MIB_IFROW mibInterface;
		memset(&mibInterface, 0, sizeof(MIB_IFROW));

		// To get a specific interface entry, just set the dwIndex
		// field before calling the GetIfEntry function
		mibInterface.dwIndex = pIpAdapterMapEntry->Index;
		if(GetIfEntry(&mibInterface) != NO_ERROR)
		   return FALSE;
		else{
			DEBUGMSG(true, (L"\tname: %s\n", mibInterface.wszName));
			DEBUGMSG(true, (L"\tindx: %u\n", mibInterface.dwIndex));
			DEBUGMSG(true, (L"\tMTU : %u\n", mibInterface.dwMtu));
			DEBUGMSG(true, (L"\tspeed:   %u\n", mibInterface.dwSpeed));
			DEBUGMSG(true, (L"======================================\n"));
			DEBUGMSG(true, (L"\top stat: %u\n", mibInterface.dwOperStatus));
			DEBUGMSG(true, (L"\tin  oct: %u\n", mibInterface.dwInOctets));
			DEBUGMSG(true, (L"\tout oct: %u\n", mibInterface.dwOutOctets));
			DEBUGMSG(true, (L"\tin  discarded: %u\n", mibInterface.dwInDiscards));
			DEBUGMSG(true, (L"\tout discarded: %u\n", mibInterface.dwOutDiscards));
			DEBUGMSG(true, (L"\tin errors:     %u\n", mibInterface.dwInErrors));
			DEBUGMSG(true, (L"\tout errors:     %u\n", mibInterface.dwOutErrors));
			if (dumpType==0)
			{
				wsprintf(str, L"\tname: %s\n", mibInterface.wszName);
				add2log(str);
				wsprintf(str, L"\tindx: %u\n", mibInterface.dwIndex);
				add2log(str);
				wsprintf(str, L"\tMTU : %u\n", mibInterface.dwMtu);
				add2log(str);
				wsprintf(str, L"\tspeed:   %u\n", mibInterface.dwSpeed);
				add2log(str);
				wsprintf(str, L"======================================\n");
				add2log(str);
				wsprintf(str, L"\top stat: %u\n", mibInterface.dwOperStatus);
				add2log(str);
				wsprintf(str, L"\tin  oct: %u\n", mibInterface.dwInOctets);
				add2log(str);
				wsprintf(str, L"\tout oct: %u\n", mibInterface.dwOutOctets);
				add2log(str);
				wsprintf(str, L"\tin  discarded: %u\n", mibInterface.dwInDiscards);
				add2log(str);
				wsprintf(str, L"\tout discarded: %u\n", mibInterface.dwOutDiscards);
				add2log(str);
				wsprintf(str, L"\tin errors:     %u\n", mibInterface.dwInErrors);
				add2log(str);
				wsprintf(str, L"\tout errors:     %u\n", mibInterface.dwOutErrors);
				add2log(str);
			}
			if ( (dumpType==1) && (wcsicmp(pIpAdapterMapEntry->Name, L"Cellular Line")==0) )
			{
				//prepare a time string
				TCHAR lpTimeStr[32];
				TCHAR lpDateStr[32];
				int res = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
										TIME_FORCE24HOURFORMAT,
										NULL,
										L"hh:mm:ss",
										lpTimeStr,
										sizeof (lpTimeStr ) * sizeof(TCHAR));
				if (res == 0)
				{
					wcscpy(lpTimeStr, L"00:00:00");
				}
				//Read the system date
				res = GetDateFormat(  LOCALE_SYSTEM_DEFAULT,
									  NULL,
									  NULL,
									  L"dd.MM.yyyy",
									  lpDateStr,
									  sizeof (lpDateStr) * sizeof(TCHAR));
				if (res == 0)
				{
					wcscpy(lpDateStr, L"01.01.1961");
				}

				wsprintf(str, L"%s\t %s\t %u\t %u\t %u\t %u\t %u\t %u\n",
									lpDateStr,
									lpTimeStr,
									mibInterface.dwSpeed, 
									mibInterface.dwOperStatus,
									mibInterface.dwInOctets,
									mibInterface.dwOutOctets,
									mibInterface.dwInErrors,
									mibInterface.dwOutErrors);
				add2log(str);
			}
		}

	}
	return true;
}

bool existFile(TCHAR f[MAX_PATH])
{
	FILE *stream;
	/* Open for read (will fail if file "data" does not exist) */
	if( (stream  = _wfopen( f, L"r" )) == NULL )
		return false;
	else
	{
		fclose(stream);
		return true;
	}
}

//global for arguments array
int          argc; 
TCHAR**       argv; 

int SplitArgs(LPTSTR lpCmdLine)
{
  unsigned int i; 
  int          j; 
  // parse a few of the command line arguments 
  // a space delimites an argument except when it is inside a quote 

  argc = 1; 
  int pos = 0; 
  for (i = 0; i < wcslen(lpCmdLine); i++) 
    { 
    while (lpCmdLine[i] == ' ' && i < wcslen(lpCmdLine)) 
      { 
      i++; 
      } 
    if (lpCmdLine[i] == '\"') 
      { 
      i++; 
      while (lpCmdLine[i] != '\"' && i < wcslen(lpCmdLine)) 
        { 
        i++; 
        pos++; 
        } 
      argc++; 
      pos = 0; 
      } 
    else 
      { 
      while (lpCmdLine[i] != ' ' && i < wcslen(lpCmdLine)) 
        { 
        i++; 
        pos++; 
        } 
      argc++; 
      pos = 0; 
      } 
    } 

  argv = (TCHAR**)malloc(sizeof(TCHAR*)* (argc+1)); 

  argv[0] = (TCHAR*)malloc(1024); 
  GetModuleFileName(0, argv[0],1024); 

  for(j=1; j<argc; j++) 
    { 
    argv[j] = (TCHAR*)malloc(wcslen(lpCmdLine)+10); 
    } 
  argv[argc] = 0; 

  argc = 1; 
  pos = 0; 
  for (i = 0; i < wcslen(lpCmdLine); i++) 
    { 
    while (lpCmdLine[i] == ' ' && i < wcslen(lpCmdLine)) 
      { 
      i++; 
      } 
    if (lpCmdLine[i] == '\"') 
      { 
      i++; 
      while (lpCmdLine[i] != '\"' && i < wcslen(lpCmdLine)) 
        { 
        argv[argc][pos] = lpCmdLine[i]; 
        i++; 
        pos++; 
        } 
      argv[argc][pos] = '\0'; 
      argc++; 
      pos = 0; 
      } 
    else 
      { 
      while (lpCmdLine[i] != ' ' && i < wcslen(lpCmdLine)) 
        { 
        argv[argc][pos] = lpCmdLine[i]; 
        i++; 
        pos++; 
        } 
      argv[argc][pos] = '\0'; 
      argc++; 
      pos = 0; 
      } 
    } 
  argv[argc] = 0; 

// Initialize the processes and start the application. 
//  retVal = MyMain(argc, argv); 

  // Delete arguments 
  TCHAR str[MAX_PATH+1];
  for(j=0; j<argc; j++) 
	{ 
		wsprintf(str, L"arg %i = %s\n", j, argv[j]);
		OutputDebugString(str);
		//free(argv[j]); 
	} 
  //free(argv); 
	return argc;
}

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	int argc;
	argc = SplitArgs(lpCmdLine); //argc is count of arguments, argv[i] are the arguments
	if (argc>=2)
	{
		if (wcsicmp(L"kill", argv[1])==0)
		{
			FILE *stream;
			stream = _wfopen ( szFlagFile, L"w" );
			if (stream != NULL)
			{
				fwprintf(stream, L"file to stop traffic logging");
				fclose(stream);
				return 1;
			}
			else
				return -2;
		}
		if (argc==3){
			DWORD d=_wtoi(argv[2]);
			if (d!=0)
				iTime = d;
		}
	}


 	// TODO: Place code here.
	//get the app dir
	TCHAR strPath[MAX_PATH];
	TCHAR startPath[MAX_PATH];
	GetModuleFileName (NULL, strPath, MAX_PATH);
	//find the last backslash
	TCHAR* p;
	if ( p = wcsrchr ( strPath, '\\')) 
		*++p = _T('\0'); // zero-terminate at the last backslash
	
	//define the log file
	wsprintf(startPath, L"%s%s", strPath, logname);
	appendfile(startPath);
	
	TCHAR str1[MAX_PATH*2];
	wsprintf(str1, L"date\t time\t speed\t status\t in\t out\t in error\t out error\n");
	add2log(str1);
	
	DWORD dwCount=0;
	do
	{
		if (dwCount == iTime){
			dumpMIBinfos(1);
			dwCount=0;
		}
		dwCount += 1;
		Sleep(1000);
	}
	while (!existFile(szFlagFile));

	//delete the flag file
	DeleteFile(szFlagFile);
	MessageBeep(MB_OK);

	return 0;
}

Open in new window

0
 
LVL 1

Author Comment

by:DareDevilE12
ID: 34894403
I will check it, but I prefer a application that will have a real time view of data use.

Best Regards
0
 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
ID: 34895727
0

Featured Post

Retailers - Is your network secure?

With the prevalence of social media & networking tools, for retailers, reputation is critical. Have you considered the impact your network security could have in your customer's experience? Learn more in our Retail Security Resource Kit Today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question