GetIcmpV4Statistics Method

IPGlobalProperties.GetIcmpV4Statistics Method ()

 

Provides Internet Control Message Protocol (ICMP) version 4 statistical data for the local computer.

Namespace:   System.Net.NetworkInformation
Assembly:  System (in System.dll)

public abstract IcmpV4Statistics GetIcmpV4Statistics()

Return Value

Type: System.Net.NetworkInformation.IcmpV4Statistics

An IcmpV4Statistics object that provides ICMP version 4 traffic statistics for the local computer.

Exception Condition
NetworkInformationException

The Win32 function GetIcmpStatistics failed.

ICMP is a set of messages for use with Internet Protocol version 4 (IPv4). ICMP is used by IPv4 nodes to report errors encountered in processing data packets and to perform other Internet layer functions. ICMP version 4 is defined in IETF RFC 792.

For details on the ICMP version 4 traffic statistics that are available to applications, see the IcmpV4Statistics class documentation. Note that the IcmpV4Statistics object returned by this method reflects the statistics as of the time the object is created. This information is not updated dynamically.

The following example displays the current ICMPv4 statistics.

public static void ShowIcmpV4Statistics()
{
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    IcmpV4Statistics stat = properties.GetIcmpV4Statistics();
    Console.WriteLine("ICMP V4 Statistics:");

    Console.WriteLine("  Messages ............................ Sent: {0,-10}   Received: {1,-10}",
        stat.MessagesSent, stat.MessagesReceived);
    Console.WriteLine("  Errors .............................. Sent: {0,-10}   Received: {1,-10}",
        stat.ErrorsSent, stat.ErrorsReceived);

    Console.WriteLine("  Echo Requests ....................... Sent: {0,-10}   Received: {1,-10}",
        stat.EchoRequestsSent, stat.EchoRequestsReceived);
    Console.WriteLine("  Echo Replies ........................ Sent: {0,-10}   Received: {1,-10}",
        stat.EchoRepliesSent, stat.EchoRepliesReceived);

    Console.WriteLine("  Destination Unreachables ............ Sent: {0,-10}   Received: {1,-10}",
        stat.DestinationUnreachableMessagesSent, stat.DestinationUnreachableMessagesReceived);

    Console.WriteLine("  Source Quenches ..................... Sent: {0,-10}   Received: {1,-10}",
        stat.SourceQuenchesSent, stat.SourceQuenchesReceived);

    Console.WriteLine("  Redirects ........................... Sent: {0,-10}   Received: {1,-10}",
        stat.RedirectsSent, stat.RedirectsReceived);  

    Console.WriteLine("  TimeExceeded ........................ Sent: {0,-10}   Received: {1,-10}",
        stat.TimeExceededMessagesSent, stat.TimeExceededMessagesReceived);

    Console.WriteLine("  Parameter Problems .................. Sent: {0,-10}   Received: {1,-10}",
        stat.ParameterProblemsSent, stat.ParameterProblemsReceived);        

    Console.WriteLine("  Timestamp Requests .................. Sent: {0,-10}   Received: {1,-10}",
        stat.TimestampRequestsSent, stat.TimestampRequestsReceived);    
    Console.WriteLine("  Timestamp Replies ................... Sent: {0,-10}   Received: {1,-10}",
        stat.TimestampRepliesSent, stat.TimestampRepliesReceived);    

    Console.WriteLine("  Address Mask Requests ............... Sent: {0,-10}   Received: {1,-10}",
        stat.AddressMaskRequestsSent, stat.AddressMaskRequestsReceived);    
    Console.WriteLine("  Address Mask Replies ................ Sent: {0,-10}   Received: {1,-10}",
        stat.AddressMaskRepliesSent, stat.AddressMaskRepliesReceived);                    
    Console.WriteLine("");
}

NetworkInformationPermission

for reading network information. Associated enumeration: Read.

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft