System.Net.IPStatistics

Microsoft Docs

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

NameTypeDescription
BytesReceivedlongTotal number of IP bytes received.
BytesSentlongTotal number of IP bytes sent.
IncomingPacketsDiscardedlongNumber of inbound packets discarded.
IncomingPacketsWithNoRoutelongNumber of inbound packets that could not be routed.
OutgoingPacketsDiscardedlongNumber of outbound packets discarded.
OutgoingPacketsWithNoRoutelongNumber of outbound packets that could not be routed.
IncomingPacketslongTotal number of inbound packets.
OutgoingPacketslongTotal number of outbound packets.
IPv4EnabledboolIndicates whether IPv4 is enabled on the local computer.
IPv6EnabledboolIndicates 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}");
    }
}

Related Topics