Ping.Send Method (IPAddress, Int32, Byte[])


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. This overload allows you to specify a time-out value for the operation.

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

public PingReply Send(
	IPAddress address,
	int timeout,
	byte[] buffer


Type: System.Net.IPAddress

An IPAddress that identifies the computer that is the destination for the ICMP echo message.

Type: System.Int32

An Int32 value that specifies the maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

Type: System.Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

Return Value

Type: System.Net.NetworkInformation.PingReply

A PingReply object that provides information about the ICMP echo reply message, if one was received, or provides the reason for the failure, if no message was received. The method will return PacketTooBig if the packet exceeds the Maximum Transmission Unit (MTU).

Exception Condition

The size of buffer exceeds 65500 bytes.


address is null.


buffer is null, or the buffer size is greater than 65500 bytes.


timeout is less than zero.


A call to SendAsync is in progress.


address is an IPv6 address and the local computer is running an operating system earlier than Windows 2000.


An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.


This object has been disposed.

If the ICMP echo reply message is not received within the time specified in the timeout parameter, the ICMP echo fails, and the Status property is set to TimedOut.


When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.

This overload uses default settings for packet fragmentation and packet forwarding. The packet that contains the ICMP echo message can be fragmented in transit if the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers. To prevent fragmentation, use one of the Send methods that takes an options parameter, and set the DontFragment property to true. When DontFragment is true and the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers, the ICMP echo request fails. When this happens, the Status is set to PacketTooBig.

The packet or packet fragments can be forwarded by routing nodes 128 times before being discarded. To change this setting, use a Send overload that takes an options parameter, and set the Ttl property to the desired value. If the packet does not reach its destination after being forwarded the specified number of times, the packet is discarded and the ICMP echo request fails. When this happens, the Status is set to TtlExpired.

The following code example demonstrates how to call this method.

public static void LocalPingTimeout ()
    // Ping's the local machine.
    Ping pingSender = new Ping ();
    IPAddress address = IPAddress.Loopback;

    // Create a buffer of 32 bytes of data to be transmitted.
    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    byte[] buffer = Encoding.ASCII.GetBytes (data);

    // Wait 10 seconds for a reply.
    int timeout = 10000;
    PingReply reply = pingSender.Send (address, timeout, buffer);

    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);
        Console.WriteLine (reply.Status);


To send an ICMP echo message.

Associated enumeration: Ping

.NET Framework
Available since 2.0
Return to top