Export (0) Print
Expand All

IPGlobalProperties.GetIPv4GlobalStatistics Method

Provides Internet Protocol version 4 (IPv4) statistical data for the local computer.

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

public abstract IPGlobalStatistics GetIPv4GlobalStatistics()

Return Value

Type: System.Net.NetworkInformation.IPGlobalStatistics
An IPGlobalStatistics object that provides IPv4 traffic statistics for the local computer.

ExceptionCondition
NetworkInformationException

The call to the Win32 function GetIpStatistics failed.

IPv4 is a network layer protocol that is responsible for routing data packets from its source computer to its destination.

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

The following code example displays IP statistics for the local computer.

public static void ShowIPStatistics(NetworkInterfaceComponent version)
{
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    IPGlobalStatistics ipstat = null;
    switch (version)
    {
        case NetworkInterfaceComponent.IPv4:
             ipstat = properties.GetIPv4GlobalStatistics();
           Console.WriteLine("{0}IPv4 Statistics ",Environment.NewLine);
            break;
        case NetworkInterfaceComponent.IPv6:
            ipstat = properties.GetIPv4GlobalStatistics();
            Console.WriteLine("{0}IPv6 Statistics ",Environment.NewLine);
            break;
        default:
            throw new ArgumentException("version");
        //    break;
    }
    Console.WriteLine("  Forwarding enabled ...................... : {0}", 
        ipstat.ForwardingEnabled);
    Console.WriteLine("  Interfaces .............................. : {0}", 
        ipstat.NumberOfInterfaces);
    Console.WriteLine("  IP addresses ............................ : {0}", 
        ipstat.NumberOfIPAddresses);
    Console.WriteLine("  Routes .................................. : {0}", 
        ipstat.NumberOfRoutes);
    Console.WriteLine("  Default TTL ............................. : {0}", 
        ipstat.DefaultTtl);
    Console.WriteLine("");    
    Console.WriteLine("  Inbound Packet Data:");
    Console.WriteLine("      Received ............................ : {0}", 
        ipstat.ReceivedPackets);
    Console.WriteLine("      Forwarded ........................... : {0}", 
        ipstat.ReceivedPacketsForwarded);
    Console.WriteLine("      Delivered ........................... : {0}", 
        ipstat.ReceivedPacketsDelivered);
    Console.WriteLine("      Discarded ........................... : {0}", 
        ipstat.ReceivedPacketsDiscarded);
    Console.WriteLine("      Header Errors ....................... : {0}", 
        ipstat.ReceivedPacketsWithHeadersErrors);
    Console.WriteLine("      Address Errors ...................... : {0}", 
        ipstat.ReceivedPacketsWithAddressErrors);
    Console.WriteLine("      Unknown Protocol Errors ............. : {0}", 
        ipstat.ReceivedPacketsWithUnknownProtocol);
    Console.WriteLine("");    
    Console.WriteLine("  Outbound Packet Data:");
    Console.WriteLine("      Requested ........................... : {0}", 
         ipstat.OutputPacketRequests);
    Console.WriteLine("      Discarded ........................... : {0}", 
        ipstat.OutputPacketsDiscarded);
    Console.WriteLine("      No Routing Discards ................. : {0}", 
        ipstat.OutputPacketsWithNoRoute);
    Console.WriteLine("      Routing Entry Discards .............. : {0}", 
        ipstat.OutputPacketRoutingDiscards);
    Console.WriteLine("");    
    Console.WriteLine("  Reassembly Data:");
    Console.WriteLine("      Reassembly Timeout .................. : {0}", 
        ipstat.PacketReassemblyTimeout);
    Console.WriteLine("      Reassemblies Required ............... : {0}", 
        ipstat.PacketReassembliesRequired);
    Console.WriteLine("      Packets Reassembled ................. : {0}", 
        ipstat.PacketsReassembled);
    Console.WriteLine("      Packets Fragmented .................. : {0}", 
        ipstat.PacketsFragmented);
    Console.WriteLine("      Fragment Failures ................... : {0}", 
        ipstat.PacketFragmentFailures);
    Console.WriteLine("");
}

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft