-1

I want to get statistics about sent and received packet counts (IP level : including TCP, UDP, etc) of a network card.

How can I query that information from windows?

F.I.V
  • 317
  • 1
  • 14

3 Answers3

0

WMI.

Not easy to use from C#, but possible.

Documentation for the needed class is at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfformatteddata_tcpip_networkinterface.asp

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • I could not manage to open the hyperlink, could you please verify it is alive – F.I.V Dec 25 '12 at 09:19
  • :I viewed the properties of Win32_PerfFormattedData_Tcpip_NetworkInterface class in MSDN, it appears most data are of type (value/s) that is packets per second or bytes per second and there is no CUMULATIVE count available? – F.I.V Dec 25 '12 at 10:25
0

First you have

using System.Net.NetworkInformation;

Next you have:

var iFaceArr = NetworkInterface.GetAllNetworkInterfaces();
NetworkInterface iface = iFaceArr[0];
IPv4InterfaceStatistics iFaceStats = iface.GetIPv4Statistics();

Then you have these variables:

iFaceStats.UnicastPacketsReceived;
iFaceStats.UnicastPacketsSent;
iFaceStats.NonUnicastPacketsReceived;
iFaceStats.NonUnicastPacketsSent;

Reference

F.I.V
  • 317
  • 1
  • 14
-1

You can take a look at Pcap.Net.

Getting the list of Live Devices on the local host.
Reading packets from Live Devices (Network Devices) and Offline Devices (Files) using the different WinPcap methods.
Receiving statistics on the entire capture.
Receiving statistics of packets instead of the full packets.
Using different sampling methods.
Applying Berkley Packet Filters.
Sending packets to Live Devices directly or using WinPcap's send queues.
Dumping packets to Pcap files.
Using Enumerables to receive packets (and LINQ).

Note that winpcap driver will have to be installed on your system.

nurettin
  • 11,090
  • 5
  • 65
  • 85
  • -1. SERIOUSLY? Install a driver for doing something that you can do out of the box with WMI? What happened to solid principles like keeping programs install only the bare necessity? – TomTom Dec 25 '12 at 07:36
  • I guess it went out with KEEP IT SIMPLE SILLY and they broke up. – nurettin Dec 25 '12 at 07:38