IPStatus 枚举

定义

报告向计算机发送 Internet 控制消息协议 (ICMP) 回送消息的状态。

public enum class IPStatus
public enum IPStatus
type IPStatus = 
Public Enum IPStatus
继承
IPStatus

字段

BadDestination 11018

由于目标 IP 地址无法收到 ICMP 回送请求或者永远都不应当出现在任何 IP 数据报的目标地址字段中,ICMP 回送请求失败。 例如,调用 Send 并指定 IP 地址“000.0.0.0”将返回此状态。

BadHeader 11042

由于标头无效,ICMP 回送请求失败。

BadOption 11007

由于包含无效选项,ICMP 回送请求失败。

BadRoute 11012

由于在源计算机和目标计算机之间没有有效的路由,ICMP 回送请求失败。

DestinationHostUnreachable 11003

由于无法访问目标计算机,ICMP 回送请求失败。

DestinationNetworkUnreachable 11002

由于无法访问包含目标计算机的网络,ICMP 回送请求失败。

DestinationPortUnreachable 11005

由于目标计算机上的端口不可用,ICMP 回送请求失败。

DestinationProhibited 11004

由于管理员禁止联系目标计算机,ICMPv6 回送请求失败。 此值仅适用于 IPv6。

DestinationProtocolUnreachable 11004

由于无法访问 ICMP 回送消息中指定的目标计算机,ICMP 回送请求失败,这是因为目标计算机不支持数据包的协议。 此值仅适用于 IPv4。 此值在 IETF RFC 1812 中描述为“Communication Administratively Prohibited”(在管理上禁止通信)。

DestinationScopeMismatch 11045

由于 ICMP 回送消息中指定的源地址和目标地址不在同一范围内,ICMP 回送请求失败。 这通常是因路由器使用了源地址范围以外的接口转发数据包而导致的。 地址范围(本地链接、本地站点和全局范围)确定地址在网络上的有效位置。

DestinationUnreachable 11040

由于无法访问 ICMP 回送消息中指定的目标计算机,ICMP 回送请求失败;此问题的确切原因未知。

HardwareError 11008

由于硬件错误,ICMP 回送请求失败。

IcmpError 11044

由于 ICMP 协议错误,ICMP 回送请求失败。

NoResources 11006

由于网络资源不足,ICMP 回送请求失败。

PacketTooBig 11009

由于包含请求的数据包的大小超过了位于源和目标之间的节点(路由器或网关)的最大传输单位 (MTU),ICMP 回送请求失败。 MTU 定义可传送数据包的最大大小。

ParameterProblem 11015

由于节点(路由器或网关)在处理数据包标头时遇到问题,ICMP 回送请求失败。 例如,当标头包含无效的字段数据或无法识别的选项时会出现这种状况。

SourceQuench 11016

由于已放弃数据包,ICMP 回送请求失败。 当源计算机的输出队列中没有足够的存储空间时,或者当数据包到达目标过快而无法进行处理时,就会发生这种情况。

Success 0

ICMP 回送请求成功;收到一个 ICMP 回送答复。 当收到此状态代码时,另一个 PingReply 属性包含有效的数据。

TimedOut 11010

在所分配的时间内未收到 ICMP 回送答复。 允许的默认答复时间为 5 秒。 可以使用带 timeout 参数的 SendSendAsync 方法更改此值。

TimeExceeded 11041

由于数据包的生存时间 (TTL) 值达到零,导致转发节点(路由器或网关)放弃数据包,ICMP 回送请求失败。

TtlExpired 11013

由于数据包的生存时间 (TTL) 值达到零,导致转发节点(路由器或网关)放弃数据包,ICMP 回送请求失败。

TtlReassemblyTimeExceeded 11014

由于数据包被分割为片段以便传输,但未在分配的时间内收到所有片段进行重组,ICMP 回送请求失败。 RFC 2460 将时间限制指定为 60 秒,必须在此时间内收到所有数据包片段。

Unknown -1

由于未知原因,ICMP 回送请求失败。

UnrecognizedNextHeader 11043

由于“下一标头”字段中没有可识别的值,ICMP 回送请求失败。 “下一标头”字段指示扩展标头类型(如果存在)或者 IP 层上的协议(例如,TCP 或 UDP)。

示例

下面的代码示例发送 ICMP 回显消息并检查状态。

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::NetworkInformation;
using namespace System::Text;

// args[1] can be an IPaddress or host name.
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   
   Ping ^ pingSender = gcnew Ping;
   PingOptions ^ options = gcnew PingOptions;
   
   // Use the default Ttl value which is 128,
   // but change the fragmentation behavior.
   options->DontFragment = true;
   
   // Create a buffer of 32 bytes of data to be transmitted.
   String^ data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   array<Byte>^buffer = Encoding::ASCII->GetBytes( data );
   int timeout = 120;
   PingReply ^ reply = pingSender->Send( args[ 1 ], timeout, buffer, options );
   
   if ( reply->Status == IPStatus::Success )
   {
      Console::WriteLine( "Address: {0}", reply->Address->ToString() );
      Console::WriteLine( "RoundTrip time: {0}", reply->RoundtripTime );
      Console::WriteLine( "Time to live: {0}", reply->Options->Ttl );
      Console::WriteLine( "Don't fragment: {0}", reply->Options->DontFragment );
      Console::WriteLine( "Buffer size: {0}", reply->Buffer->Length );
   }

   
}
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        // args[0] can be an IPaddress or host name.
        public static void Main (string[] args)
        {
            Ping pingSender = new Ping ();
            PingOptions options = new PingOptions ();

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            int timeout = 120;
            PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine ("Address: {0}", reply.Address.ToString ());
                Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
                Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
                Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
                Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
            }
        }
    }
}

注解

Ping 类使用此枚举中的值来设置 PingReply.Status 属性。 调用或Ping.SendAsync方法时Ping.Send,类PingPingReply返回对象,以检查是否可以通过网络访问计算机。

警告

DestinationProhibited 和 DestinationProtocolUnreachable 枚举值具有相同的数值。 这是可能的,因为 DestinationProhibited 仅适用于 IPv6,DestinationProtocolUnreachable 仅适用于 IPv4。

适用于