Overview
The System.Net.IPStatistics
class provides statistical data for IP (Internet Protocol) operations on the local computer. It is returned by IPGlobalProperties.GetIPv4Statistics()
and IPGlobalProperties.GetIPv6Statistics()
.
Properties
Name | Type | Description |
---|---|---|
BytesReceived | long | Total number of IP bytes received. |
BytesSent | long | Total number of IP bytes sent. |
IncomingPacketsDiscarded | long | Number of inbound packets discarded. |
IncomingPacketsWithNoRoute | long | Number of inbound packets that could not be routed. |
OutgoingPacketsDiscarded | long | Number of outbound packets discarded. |
OutgoingPacketsWithNoRoute | long | Number of outbound packets that could not be routed. |
IncomingPackets | long | Total number of inbound packets. |
OutgoingPackets | long | Total number of outbound packets. |
IPv4Enabled | bool | Indicates whether IPv4 is enabled on the local computer. |
IPv6Enabled | bool | Indicates whether IPv6 is enabled on the local computer. |
Example
using System;
using System.Net.NetworkInformation;
class Program
{
static void Main()
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
// IPv4 statistics
IPStatistics ipv4 = properties.GetIPv4Statistics();
Console.WriteLine($"IPv4 Bytes Received: {ipv4.BytesReceived}");
Console.WriteLine($"IPv4 Bytes Sent: {ipv4.BytesSent}");
// IPv6 statistics
IPStatistics ipv6 = properties.GetIPv6Statistics();
Console.WriteLine($"IPv6 Bytes Received: {ipv6.BytesReceived}");
Console.WriteLine($"IPv6 Bytes Sent: {ipv6.BytesSent}");
}
}