Click or drag to resize

NetworkStatisticInfoProvider Constructor

Initializes a new instance of the NetworkStatisticInfoProvider class.

Namespace:  Xcalibur.WMI.Hardware.Network
Assembly:  Xcalibur.WMI (in Xcalibur.WMI.dll) Version: 3.0.0.0 (3.0.1.0)
Syntax
public NetworkStatisticInfoProvider(
	ManagementScope ms,
	string deviceName = ""
)

Parameters

ms
Type: System.ManagementManagementScope
The management scope.
deviceName (Optional)
Type: SystemString
Name of the network device.
Examples
C#
 1// Main
 2private static void Main()
 3{
 4    // Make a connection to the local machine
 5    const string computer = ".";
 6    var managementScope = new ManagementScope($@"\\{computer}\root\cimv2", new ConnectionOptions
 7    {
 8        Impersonation = ImpersonationLevel.Impersonate,
 9        Authentication = AuthenticationLevel.Connect
10    });
11    managementScope.Connect();
12
13    // Network Statistic Info Provider
14    var provider = new NetworkStatisticInfoProvider(managementScope);
15
16    // Fetch data
17    provider.Refresh();
18
19    // Print
20    foreach (var info in provider.Results)
21    {
22        Console.WriteLine($"Device Name: \t\t{info.Name}");
23        Console.WriteLine($"Bytes Received/s: \t{info.BytesReceivedPerSec:n0}");
24        Console.WriteLine($"Bytes Sent/s: \t\t{info.BytesSentPerSec:n0}");
25        Console.WriteLine($"Total Bytes/s: \t\t{info.BytesTotalPerSec:n0}");
26        Console.WriteLine($"Packets/s: \t\t{info.PacketsPerSec:n0}");
27        Console.WriteLine($"Packets Sent/s: \t{info.PacketsSentPerSec:n0}");
28        Console.WriteLine($"Packets Received/s: \t{info.PacketsReceivedPerSec:n0}");
29        Console.WriteLine("");
30    } 
31
32    // Read
33    Console.Read();
34
35/* Results: 
36 * 
37 * Device Name:            Intel[R] Ethernet Connection [2] I219-V
38 * Bytes Received/s:       2,798,696,665
39 * Bytes Sent/s:           213,876,403
40 * Total Bytes/s:          3,012,573,068
41 * Packets/s:              4,422,571
42 * Packets Sent/s:         1,998,994
43 * Packets Received/s:     2,423,577
44 * 
45 * Device Name:            Local Area Connection* 9
46 * Bytes Received/s:       5,621
47 * Bytes Sent/s:           1,019,789
48 * Total Bytes/s:          1,025,410
49 * Packets/s:              7,594
50 * Packets Sent/s:         7,546
51 * Packets Received/s:     48
52 * 
53 */
See Also