IPGlobalProperties.GetIPv4GlobalStatistics 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供本地计算机的 Internet 协议版本 4 (IPv4) 统计数据。
public:
abstract System::Net::NetworkInformation::IPGlobalStatistics ^ GetIPv4GlobalStatistics();
public abstract System.Net.NetworkInformation.IPGlobalStatistics GetIPv4GlobalStatistics ();
abstract member GetIPv4GlobalStatistics : unit -> System.Net.NetworkInformation.IPGlobalStatistics
Public MustOverride Function GetIPv4GlobalStatistics () As IPGlobalStatistics
返回
一个 IPGlobalStatistics 对象,提供本地计算机的 IPv4 流量统计数据。
例外
调用 Win32 函数 GetIpStatistics
失败。
示例
下面的代码示例显示本地计算机的 IP 统计信息。
void ShowIPStatistics( NetworkInterfaceComponent version )
{
IPGlobalProperties ^ properties = IPGlobalProperties::GetIPGlobalProperties();
IPGlobalStatistics ^ ipstat = nullptr;
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 gcnew 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( "" );
}
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.GetIPv6GlobalStatistics();
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("");
}
注解
IPv4 是一种网络层协议,负责将数据包从源计算机路由到目标。
有关应用程序可用的 IP 流量统计信息的详细信息,请参阅 IPGlobalStatistics 类文档。 请注意,此方法返回的对象反映了创建对象时的 IPGlobalStatistics 统计信息。 此信息不会动态更新。