Ping Multiple IP’s from a Windows Command Prompt

Here is a very easy script for windows CMD line to ping multiple IP addresses very quickly and output the results as a file. This is really nice for doing ping tests from remote servers so you don’t have to install any software.

1) I used Excel and created a list of IP’s I want to pingExcel Example
a. Open excel, type in the first IP in the range of IP’s you want to ping.
b. If you grab the bottom right hand of the cell (you will see a + sign) and pull down, it will auto fill the next number in the range and just keep pulling down until you have all the IP’s you want.

c. Highlight all the IP’s and copy them to the clipboard.

 

 

2)     Open a new text file.  Paste your list of IP’s, one IP address per line (it should past like that).

3)     Save your text file to an easy directory to remember.  Name the text file something easy, like “servers.txt”

4)     Open up the command prompt

5)     Change directory in the command prompt that holds your text file with the IP’s you just created.

6)     Copy and paste the following line and hit enter:

for /f “tokens=1” %a in (<your txt file>.txt) DO @ping -n 1 %a  >> output.txt

a.  NOTE: the <your txt file> above should be replaced with the name of the text file you createdCommand Prompt Example

7)     Now, navigate to the directory in Windows Explorer where you saved your IP text file.  You should see the file “output.txt”

8)     If you open that up, you should now see the output of your ping commands, for each server you had in your IP text file.  It would look like this:example3

 

, the above script only sends one icmp packet to each IP you list.  Now, that’s probably good for just seeing if the IP is used or not.  You may want to increase the number of ICMP packets sent to each server.  You can do that by changing the following in the script:

1)     Instead of “for /f “tokens=1” %a in (<your txt file>.txt) DO @ping -n 1 %a  >> output.txt”

  1. Change the “@ping –n 1 %a” to “ping –n <#> %a” where the “<#>” being the number of pings you want to send.

, if you modified the script to read “for /f “tokens=1” %a in (<your txt file>.txt) DO @ping -n 5 %a  >> output.txt then you will get:

Pinging 192.37.90.1 with 32 bytes of data:
Reply from 10.5.88.254: bytes=32 time=33ms TTL=250
Reply from 10.5.88.254: bytes=32 time=33ms TTL=250
Reply from 10.5.88.254: bytes=32 time=33ms TTL=250
Reply from 10.5.88.254: bytes=32 time=31ms TTL=250
Reply from 10.5.88.254: bytes=32 time=33ms TTL=250

Ping statistics for 192.37.90.1:
Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 31ms, Maximum = 33ms, Average = 32ms

Pinging 192.37.90.2 with 32 bytes of data:
Reply from 10.5.88.253: bytes=32 time=32ms TTL=250
Reply from 10.5.88.253: bytes=32 time=31ms TTL=250
Reply from 10.5.88.253: bytes=32 time=32ms TTL=250
Reply from 10.5.88.253: bytes=32 time=31ms TTL=250
Reply from 10.5.88.253: bytes=32 time=31ms TTL=250

Ping statistics for 192.37.90.2:
Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 31ms, Maximum = 32ms, Average = 31ms

Very simple and you don’t need to install anything. Hope this is useful!

6 thoughts on “Ping Multiple IP’s from a Windows Command Prompt

    • Since you won’t know what your latency is till after the pings have been sent you can’t filter your list to ping only those address, you need to ping them all. After you get your results from the ping you would need to write a script to filter output.txt or redirect your output to a script and only display out the IPs that have ping times over 1000ms.

  1. Hi , commands above worked like a charm for me .

    This idea could be perfect if we can make a batch file for the whole process . Just double click the batch file and it pings all the ip’s from a defined ip list .

    Is it possible ?

    Thanks & Regards,
    Rahul

    • I have it setup that way and it works no problems. Just need to make sure your batch file and servers.txt file are in the same directory.

Leave a Reply

Your email address will not be published. Required fields are marked *