[C# ] 执行ping命令,获得网络状态

代码:

string  ipStr = "192.168.1.10";            
Ping p1 = new Ping();
PingReply reply = p1.Send(ip);


reply返回的状态:


public enum IPStatus
    {
        //
        // 摘要:
        //     The ICMP echo request succeeded; an ICMP echo reply was received. When you get
        //     this status code, the other System.Net.NetworkInformation.PingReply properties
        //     contain valid data.
        Success = 0,
        //
        // 摘要:
        //     The ICMP echo request failed because the network that contains the destination
        //     computer is not reachable.
        DestinationNetworkUnreachable = 11002,
        //
        // 摘要:
        //     The ICMP echo request failed because the destination computer is not reachable.
        DestinationHostUnreachable = 11003,
        //
        // 摘要:
        //     The ICMP echo request failed because the destination computer that is specified
        //     in an ICMP echo message is not reachable, because it does not support the packet's
        //     protocol.
        DestinationProtocolUnreachable = 11004,
        //
        // 摘要:
        //     The ICMP echo request failed because the port on the destination computer is
        //     not available.
        DestinationPortUnreachable = 11005,
        //
        // 摘要:
        //     The ICMP echo request failed because contact with the destination computer is
        //     administratively prohibited.
        DestinationProhibited = 11004,
        //
        // 摘要:
        //     The ICMP echo request failed because of insufficient network resources.
        NoResources = 11006,
        //
        // 摘要:
        //     The ICMP echo request failed because it contains an invalid option.
        BadOption = 11007,
        //
        // 摘要:
        //     The ICMP echo request failed because of a hardware error.
        HardwareError = 11008,
        //
        // 摘要:
        //     The ICMP echo request failed because the packet containing the request is larger
        //     than the maximum transmission unit (MTU) of a node (router or gateway) located
        //     between the source and destination. The MTU defines the maximum size of a transmittable
        //     packet.
        PacketTooBig = 11009,
        //
        // 摘要:
        //     The ICMP echo Reply was not received within the allotted time. The default time
        //     allowed for replies is 5 seconds. You can change this value using the Overload:System.Net.NetworkInformation.Ping.Send
        //     or Overload:System.Net.NetworkInformation.Ping.SendAsync methods that take a
        //     timeout parameter.
        TimedOut = 11010,
        //
        // 摘要:
        //     The ICMP echo request failed because there is no valid route between the source
        //     and destination computers.
        BadRoute = 11012,
        //
        // 摘要:
        //     The ICMP echo request failed because its Time to Live (TTL) value reached zero,
        //     causing the forwarding node (router or gateway) to discard the packet.
        TtlExpired = 11013,
        //
        // 摘要:
        //     The ICMP echo request failed because the packet was divided into fragments for
        //     transmission and all of the fragments were not received within the time allotted
        //     for reassembly. RFC 2460 (available at www.ietf.org) specifies 60 seconds as
        //     the time limit within which all packet fragments must be received.
        TtlReassemblyTimeExceeded = 11014,
        //
        // 摘要:
        //     The ICMP echo request failed because a node (router or gateway) encountered problems
        //     while processing the packet header. This is the status if, for example, the header
        //     contains invalid field data or an unrecognized option.
        ParameterProblem = 11015,
        //
        // 摘要:
        //     The ICMP echo request failed because the packet was discarded. This occurs when
        //     the source computer's output queue has insufficient storage space, or when packets
        //     arrive at the destination too quickly to be processed.
        SourceQuench = 11016,
        //
        // 摘要:
        //     The ICMP echo request failed because the destination IP address cannot receive
        //     ICMP echo requests or should never appear in the destination address field of
        //     any IP datagram. For example, calling Overload:System.Net.NetworkInformation.Ping.Send
        //     and specifying IP address "000.0.0.0" returns this status.
        BadDestination = 11018,
        //
        // 摘要:
        //     The ICMP echo request failed because the destination computer that is specified
        //     in an ICMP echo message is not reachable; the exact cause of problem is unknown.
        DestinationUnreachable = 11040,
        //
        // 摘要:
        //     The ICMP echo request failed because its Time to Live (TTL) value reached zero,
        //     causing the forwarding node (router or gateway) to discard the packet.
        TimeExceeded = 11041,
        //
        // 摘要:
        //     The ICMP echo request failed because the header is invalid.
        BadHeader = 11042,
        //
        // 摘要:
        //     The ICMP echo request failed because the Next Header field does not contain a
        //     recognized value. The Next Header field indicates the extension header type (if
        //     present) or the protocol above the IP layer, for example, TCP or UDP.
        UnrecognizedNextHeader = 11043,
        //
        // 摘要:
        //     The ICMP echo request failed because of an ICMP protocol error.
        IcmpError = 11044,
        //
        // 摘要:
        //     The ICMP echo request failed because the source address and destination address
        //     that are specified in an ICMP echo message are not in the same scope. This is
        //     typically caused by a router forwarding a packet using an interface that is outside
        //     the scope of the source address. Address scopes (link-local, site-local, and
        //     global scope) determine where on the network an address is valid.
        DestinationScopeMismatch = 11045,
        //
        // 摘要:
        //     The ICMP echo request failed for an unknown reason.
        Unknown = -1
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值