PING – Windows CMD Command
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 0Therefore 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 a 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 successfully 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, traveling 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 administrators 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 Serverf4t
Check if a host is reachable:
PING Serverf4t |find "TTL=" && ECHO MyHost found
Check if a host is not reachable:
PING Serverf4t |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.
Having read this I thought it was rather enlightening.
I appreciate you taking the time and effort to put this
content together. I once again find myself spending a lot
of time both reading and commenting. But so what, it was still worth it!
Yes! Finally someone writes about website.
optimal content, i like it
superb article, i like it
complete content, i like it
fabulous article, i like it
I like the valuable information you provide in your articles.
I will bookmark your weblog and check again here regularly.
I’m quite sure I will learn plenty of new stuff right here!
Good luck for the next!
I dugg some of you post as I cerebrated they were handy very beneficial
It’s in point of fact a great and useful piece of information. I am satisfied that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.
Howdy! This post couldn’t be written any better!
Reading through this post reminds me of my previous room
mate! He always kept chatting about this.
I will forward this post to him. Fairly certain he will have a good read.
Thank you for sharing!
My spouse and I stumbled over here coming from a
different website and thought I might as well check things out.
I like what I see so now i’m following you. Look forward to exploring your web page repeatedly.
Like!! Thank you for publishing this awesome article.