Programming Field

Ping (Network connectivity check) - DOS/Command Prompt Reference

[Windows 95 or later] Sends ICMP echo request packets to a specified host to verify network connectivity, response time, and packet loss.

Syntax

ping[.exe] [-t] [-a] [-n <count>] [-l <size>] [-f] [-i <TTL>] [-v <TOS>]
    [-r <count>] [-s <count>] [-j <host-list>] [-k <host-list>] [-w <timeout>]
    [-R] [-S <source-address>] [-4] [-6]
    [-c <compartment>] [-p] <destination>

Options

<destination> Specifies the destination address to send echo requests to, either as an IP address or hostname.
-t Sends echo requests to the specified host continuously until stopped by the user (by pressing Ctrl+C).
-a Resolves the hostname for the specified IP address, if <destination> is an IP address.
-n <count> Specifies the number of echo requests to send. The default is 4.
-l <size> Specifies the size of the packets to send. The default is 32 bytes.
-f Sets the ‘Don't Fragment’ flag in the packet. If the packet cannot be sent at the specified size without fragmentation, it is discarded.
-i <TTL> Specifies the Time To Live (TTL) for the packet. The default is 128.
-v <TOS> Specifies the Type of Service (TOS) field in the packet. Currently ignored.
-r <count> Records the route of the packet through routers. The maximum value for <count> is 9.
-s <count> Records timestamps for the number of hops specified. The maximum value is 4.
-j <host-list> Uses loose source routing along the specified host list. The <host-list> is a series of IP addresses separated by commas.
-k <host-list> Uses strict source routing along the specified host list. The <host-list> is a series of IP addresses separated by commas.
-w <timeout> Specifies the timeout in milliseconds to wait for each reply. The default is 4000 milliseconds (4 seconds).
-R [Windows Vista or later] Adds the route record option to the IPv6 header, if IPv6 is used.
-S <source-address> [Windows Vista or later] Specifies the source address to use.
-4 [Windows Vista or later] Forces the use of IPv4.
-6 [Windows Vista or later] Forces the use of IPv6.
-c <compartment> [Windows 10? or later] Specifies the routing compartment identifier. Ping will be executed within the specified compartment.
-p [Windows 10? or later] Pings the Hyper-V Network Virtualization provider address.

Details

The ping command sends ICMP echo request packets to a specified host and measures the time it takes for a response, as well as packet loss. This helps in assessing network connectivity and connection quality.

An ICMP echo request is a protocol used to check network connectivity by sending a request to a host and waiting for a reply. Unlike HTTP requests that aim to retrieve data from web servers, ICMP echo requests simply check for a response to verify the connection status. While ICMP is supported by most hosts, some may disable responses to echo requests for security reasons. Therefore, a lack of response does not necessarily indicate a network issue.

For the -j and -k options, the host list should consist of IP addresses separated by commas. Hostnames are not supported. The order of addresses in the list is critical to ensure the packet follows the intended route. An incorrect order may result in unintended routing.

Samples

Sample 1

ping www.example.com

Sends 4 echo requests to the host www.example.com and displays the response time.

Sample 2

ping -t 192.168.1.1

Sends echo requests to the IP address 192.168.1.1 continuously until manually stopped.

Sample 3

ping -n 10 -l 64 www.example.com

Sends 10 echo requests with 64-byte packets to the host www.example.com.

See also