Click here to Skip to main content
Click here to Skip to main content

TrafficWatcher

By , 15 Nov 2002
 

Sample Image

Description

TrafficWatch is a small utility to get information about the amount of data transferred to and from the internet. It uses the WinPcap library from http://winpcap.polito.it/docs/default.htm. Network traffic inside a LAN is ignored - only IP packets going through the standard gateway are measured. Traffic is also measured by service: FTP, mail, news, web, UDP and others. So you can see for what you need your internet connection.

Why?

Flat rates are getting more common these days. ISPs often offer them only up to a specified amount of traffic - additional transferred data must be paid extra. So I wanted to know exactly how much traffic I use/need to decide which ISP and which offer I wanted. And of course I'm curious :)

Sample Image

Implementation

To gather only the internet traffic and ignore traffic inside LAN I needed a way to analyse every IP data packet entering or leaving the network interface. The WinPcap library is used to catch all these packets. Then the program analyses the captured packets by source and destination IP and port. With these data the program builds the statistics.

Other tools

There are other tools in this utility: Ping, Traceroute, Connection Information and Whois. The Whois-utility uses a text file to determine which server to ask for specific TLD's. The one offered with this utility is far from complete. If someone wants to complete it, please send me a copy!

Installation

An installer is provided. If you don't have WinPcap already installed, you must either download it from http://winpcap.polito.it/docs/default.htm or let the installer install it for you. After installation you should maybe restart your computer to proper initialize the WinPcap drivers - otherwise the program may crash.

Notes

For this tool I used many classes and tips from this website. Some of them are unchanged, some of them I changed a little or more. This tool is also kind of a try out project for me - whenever I want to try out some API's or functions I add them to this tool. An example of that you can see in the "About" pane. So please don't blame me if some things are not perfectly coded.

Update

16.11.02 fixed several bugs where the prog crashed on startup (I hope :). Also the statistics page now shows a red line in the bars to separate up from downloads.

22.6.02 corrected a bug where the statistics weren't correctly cleaned up. Fixed a bug where the program crashed when more than 10 adapters were found. Also fixed missing files in source.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

SteveKing
Software Developer
Switzerland Switzerland
Member
---

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generala version that works on VistamemberSteveKing23 Apr '09 - 19:40 
My changes to this tool to make it work on Vista can be found here[^]
QuestionRe: a version that works on VistamemberDavid Reis3 May '09 - 7:18 
This nice, but.... What happened to the Tools page (Ping, WHOIS and TraceRoute)?
GeneralMy vote of 2memberElmue16 Jan '09 - 4:46 
Does not work
GeneralDoes not functionmemberElmue27 Mar '08 - 22:35 
Hello
 
I have two programs which run fine using WinPCap. (Packetyzer (www.packetyzer.com) and this tool: http://www.codeproject.com/KB/IP/apptraffwatcher.aspx[^])
 
But your application does not even list the network adapter in the last tab.
It simply does not show anything (traffic = 0)
 
When starting it the second time it tells me:
"Could not open Adapter in CPacket::Open()"
and instead of letting me configure the program it closes. (a maldesign)
 
Elmü
AnswerRe: Does not function [modified]membero-lox15 Jan '09 - 5:08 
The same problem was found on my computer.
 
I have corrected AdapterString = "\\DEVICE\\NPF_"+.. in file
Packet.cpp in function CPacket::init() and now it is working(found LAN), but with reserve. It falls every 10 seconds whenever I watch it. There must be more mistakes in that code.
Confused | :confused: should check it and see later..
 
I have it.
so I add directive i=-1; to start function BOOL CPacket::Open (identical file) and it seems to be OK.
 
Great program (i am only missing using for earth.jpg)
 
modified on Thursday, January 15, 2009 12:47 PM

QuestionDoes this work on Windows Vista?memberDallas at Ekky25 Aug '07 - 18:04 
Hello All,
 
Does this work on Windows Vista?
 
Thanks,
Dallas.
 
http://www.ekkySoftware.com/
GeneralNot working on x64 systemsmembermanfbraun8 Apr '07 - 12:18 
Hi !
 
I am using Windows Server 2003 x64 Edition and it does not work;
"could not open Adapter in CPacket::Open()".
I've installed PCap 4.0, which support x64 and wireshark/ethereal is working.
Too much interop in that project?
 
Best regards,
Manfred

 
Ciao,
mb

QuestionHow to Compile in VC++ 6 !memberInyong Jeong26 Apr '06 - 20:56 
How to Compile in VC++ 6?
 
STEP 1. first, Convert workspace VC++7 to VC++6(.dsw, .dsp) - You can use prjconverter from "http://www.codeproject.com/tools/prjconverter.asp" to convert the project to a VC++ 6 project
 
STEP 2. DOWNLOAD PSDK(Windows Server 2003 SP1 Platform SDK) and install
- we can download PSDK from http://www.microsoft.com/downloads/details.aspx?familyid=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en
 
STEP 3. Run VC++ and load this project workspace file(trafficwatch.dsw)
 
STEP 4. Change VC++ Environments
- we have to include INCLUDE and LIB folder of PSDK
a. select menu on VC++ : "Tools -> Options..."
b. select "Directories" on options tab control
(1) select "Include Files" on combobox "Show directories..."
(2) find and select PSDK INCLUDE folder
(ex) "C:\PROGRAM FILES\MICROSOFT PLATFORM SDK\INCLUDE"
(3) we must move to first position this path item
(4) select "Library Files" on combobox "Show directories..."
(5) find and select PSDK LIB folder
(ex)C:\PROGRAM FILES\MICROSOFT PLATFORM SDK\LIB
(6) click "OK"
 
STEP 5. Now, edit some source code - because it is VC++ 7 based project
a. When compiling I get the error :
"c:\program files\microsoft platform
sdk\include\wspiapi.h(45) : error C2265: '' : reference to a
zero-sized array is illegal "
[Resolution] : Try to define _WSPIAPI_COUNTOF before #include "Ws2tcpip.h" (maybe,it is appear 3 times)
(ex)
#define _WSPIAPI_COUNTOF //here
#include "Ws2tcpip.h"
 
b. error C2039: 'Trim' : is not a member of 'CString'
[Resolution] : Trim() function is not a member of 'CString'
we need to replace this function by TrimRight() and TrimLeft()
(ex) lat = atof(answer.Right(answer.GetLength()-index-4).Trim());
To:
CString str = answer.Right(answer.GetLength()-index-4);
str.TrimLeft(); str.TrimRight();
lat = atof(str);
 
c. error C2039: 'GetCount' : is not a member of 'CArray'
[Resolution] : GetCount() function is not a member of CArray
we have to replace this function by GetSize()


(ex) for (int i=0; i<m_longitude.GetCount(); i++)
To: for (int i=0; i<m_longitude.GetSize(); i++)
 

STEP 6. excute WinPcap_2_3_nogui.exe (Project source folder)
for copy wpcap.dll to system32 foder
 
STEP 7. OK!! Now is the time to built and test Blush | :O

 
have a good time!!
 
-- modified at 5:17 Thursday 27th April, 2006
AnswerRe: How to Compile in VC++ 6 !memberddas7730 Aug '07 - 3:34 
Thanks for your comment. I was unable to compile a program I wrote that included the WS2tcpip.h header file in VC++ 6. The compiler was complaining with:
 
wspiapi.h(45) : error C2265: '<Unknown>' : reference to a zero-sized array is illegal
 
That is, unless I got the tip to define _WSPIAPI_COUNTOF from your comment. Now it compiles.
 
Thanks again. Cheereo. Rose | [Rose]
 

Generalworks with VC2002 and WinPCap 3.1membereurocent19 Apr '06 - 1:50 
change following lines: in Packet.CPP
"Adapters[nAdapterCount].AdapterString = "\\Device\\Packet_" + Adapters[nAdapterCount].AdapterString;" to
"Adapters[nAdapterCount].AdapterString = "\\Device\\NPF_" + Adapters[nAdapterCount].AdapterString;"
 
"BOOLEAN PacketGetNetInfo(LPTSTR AdapterName, PULONG netp, PULONG maskp);" to
"BOOLEAN PacketGetNetInfoEx(LPTSTR AdapterName, PULONG netp, PULONG maskp);"
 
To compile use then new Libraries from WinPCap 3.1
 

 
Mfg Druschel
 
-- modified at 7:53 Wednesday 19th April, 2006

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 16 Nov 2002
Article Copyright 2002 by SteveKing
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid