PING

Test a network connection - if successful, ping returns the ip address.

Syntax
      PING [options] destination_host

Options
    -w timeout     Timeout in milliseconds to wait for each reply, default=4000.
    -i TTL         Time To Live.
    -v TOS         Type Of Service.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -t             Ping the destination host until interrupted.
                   To see statistics and continue type Control-Break;
                   To stop type Control-C.
    -l size        Send buffer size (default=32).
    -f             Set don’t Fragment flag in packet (IPv4-only).
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host_list   Loose source route along host_list (IPv4-only).
    -k host_list   Strict source route along host_list (IPv4-only).
 destination_host  The name of the remote host
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.

A response of "Request timed out" means there was no response within the default time period.

A successful PING does NOT always return an %errorlevel% of 0
Therefore to reliably detect a successful ping, pipe the output into FIND and look for the text "TTL"

Note that "Reply" in the output of PING does not always indicate a positive response.
Example message: Reply from 192.168.1.254: Destination Net Unreachable.

Ping defaults to an ICMP timeout of 4000ms or 4 seconds. When specifying very small numbers (<500) for timeout with -w , the Ping reply can be received even if timeout milliseconds have elapsed.

Timeout

When pinging a host that doesn’t exist or is offline there will be a delay of some seconds before it is returned as 'host not found'.

The PING -w and the WMI Get-CIMInstance Win32_PingStatus timeout=NNN options both offer to control the Timeout, but this is the ICMP timeout not the DNS client timeout.

When sucessfully contacting a host, the ICMP timeout is used (default typically 4 seconds) but when attempting to PING a non-existent or offline computer it will be a DNS timeout causing the delay, typically around 9 - 10 seconds.

The time to respond as 'host not found' is for the first response, once you have pinged a host once, DNS will cache the (non) response and respond much faster to a second PING.

The performance of PING, Get-CIMinstance, PSPING and Test-Connection (PowerShell) are all comparable, the only difference being that PING and Get-CIMinstance allow modifying the ICMP timeout.

How to test connectivity with ping:

1) Ping the loopback address to verify that TCP/IP is installed and configured correctly on the local computer.
PING 127.0.0.1

2) Ping the IP address of the local computer to verify that it was added to the network correctly.
PING IP_address_of_local_host

3) Ping the IP address of the default gateway to verify that the default gateway is functioning and that you can communicate with a local host on the local network.
PING IP_address_of_default_gateway

4) Ping the IP address of a remote host to verify that you can communicate through a router.
PING IP_address_of_remote_host

Use PING to create a time delay:

Create a delay of 1 or more seconds by pinging the loopback address (127.0.0.1) multiple times.
The delay between each ping is 1 second, so for a delay of 5 seconds ping 6 times:
PING -n 6 127.0.0.1>nul
In tests this consumes less processor time than Sleep or Timeout - see Clay Calvert's original newsgroup posting.

Ping response times below 10 milliseconds often have low accuracy. A time of 10 milliseconds is roughly equal to a distance of 1860 Miles, travelling a straight line route at the speed of light, (or a round trip of 2 × 930 miles). From this you can see that ping response times will give a very very rough estimate of the distance to a remote host.

Network adminstrators do not appreciate frequent or continual pings to their servers, try not to overdo it!

The IPv6 options are only available on versions of Windows that support IPv6.

Examples

Ping a server just once:

PING -n 1 Server64

Check if a host is reachable:

PING Server64 |find "TTL=" && ECHO MyHost found

Check if a host is not reachable:

PING Server64 |find "TTL=" || ECHO MyHost not found

Test which iSCSI IP on a specific NIC is functioning or if a specific teamed NIC is operating as it should:

Ping -S (Source IP: XXX.XXX.XXX.XXX) (Destination IP: XXX.XXX.XXX.XXX)
Ping -S 10.5.7.64  10.5.7.1

Ping a website 5 times:

PING -n 5 -w 7500 www.microsoft.com

Monitor a website (example.com) every 15 seconds:

@Echo off
Echo Logging ping responses, press CTRL-C to stop
:start
 Ping -n 1 example.com | find "TTL=" >>c:\pingtest.txt
 Echo .
 Ping -n 16 127.0.0.1>nul
goto start

The script above can be used to test an Internet connection, just replace example.com with your ISP's Default Gateway IP address. This represents the first physical device on the ISP's side of your connection. You can find the Default Gateway on your router status screen.

PING is named after the sound that a sonar makes.

“And now I see with eye serene
The very pulse of the machine” ~ William Wordsworth, (She Was a Phantom of Delight)

Related commands

TRACERT - Trace route to a remote host.
IPCONFIG - IP Configuration.
PATHPING - Route Tracing tool.
Q115388 - Resolving IP Address with Leading Zero.
FreePing - Freeware Windows GUI Ping.
LocaPing - Online ping.
RFC5737 - IPv4 Address Blocks Reserved for Documentation.
Equivalent PowerShell: Test-Connection - Ping one or more computers, psp function.
Equivalent bash command (Linux): ping - Test a network connection.


 
Copyright © 1999-2024 SS64.com
Some rights reserved