I want a windows command line script that will ping a range of ips in a specified subnet, does anyone know if one?

I want a windows command line script that will ping a range of ips in a specified subnet, does anyone know if one?

Thank you,
dsterlingAsked:
Who is Participating?
 
Harper McDonaldCommented:
So it will ping 1-254 in the last octet of that one subnet

PS C:\> .\ping.ps1
Reply from 172.18.4.25: bytes=32 time=2ms TTL=64
Reply from 172.18.4.35: bytes=32 time<1ms TTL=64
Reply from 172.18.4.36: bytes=32 time<1ms TTL=64
Reply from 172.18.4.43: bytes=32 time=1ms TTL=128
Reply from 172.18.4.52: bytes=32 time=1ms TTL=255
Reply from 172.18.4.74: bytes=32 time=1ms TTL=128
Reply from 172.18.4.77: bytes=32 time<1ms TTL=128
Reply from 172.18.4.103: bytes=32 time=2ms TTL=128
Reply from 172.18.4.105: bytes=32 time=1ms TTL=128
Reply from 172.18.4.106: bytes=32 time=1ms TTL=128
Reply from 172.18.4.107: bytes=32 time<1ms TTL=128
Reply from 172.18.4.110: bytes=32 time=1ms TTL=128
Reply from 172.18.4.112: bytes=32 time=5ms TTL=128
Reply from 172.18.4.117: bytes=32 time=1ms TTL=128
Reply from 172.18.4.118: bytes=32 time=1ms TTL=128
Reply from 172.18.4.120: bytes=32 time<1ms TTL=64
Reply from 172.18.4.122: bytes=32 time=1ms TTL=128
Reply from 172.18.4.123: bytes=32 time<1ms TTL=128
Reply from 172.18.4.129: bytes=32 time=2ms TTL=128
Reply from 172.18.4.135: bytes=32 time<1ms TTL=128
Reply from 172.18.4.141: bytes=32 time<1ms TTL=128
Reply from 172.18.4.142: bytes=32 time=1ms TTL=128
Reply from 172.18.4.144: bytes=32 time=1ms TTL=128
Reply from 172.18.4.149: bytes=32 time<1ms TTL=128
Reply from 172.18.4.150: bytes=32 time=1ms TTL=128
Reply from 172.18.4.151: bytes=32 time=1ms TTL=128
Reply from 172.18.4.152: bytes=32 time=1ms TTL=128
Reply from 172.18.4.155: bytes=32 time=1ms TTL=128
Reply from 172.18.4.156: bytes=32 time=1ms TTL=128
Reply from 172.18.4.157: bytes=32 time=1ms TTL=128
Reply from 172.18.4.161: bytes=32 time<1ms TTL=128
Reply from 172.18.4.162: bytes=32 time=1ms TTL=128
Reply from 172.18.4.163: bytes=32 time<1ms TTL=128
Reply from 172.18.4.167: bytes=32 time=1ms TTL=128
Reply from 172.18.4.178: bytes=32 time=1ms TTL=128
Reply from 172.18.4.180: bytes=32 time<1ms TTL=128
Reply from 172.18.4.181: bytes=32 time=1ms TTL=128
Reply from 172.18.4.182: bytes=32 time<1ms TTL=64
Reply from 172.18.4.184: bytes=32 time=1ms TTL=64
Reply from 172.18.4.191: bytes=32 time<1ms TTL=128
Reply from 172.18.4.192: bytes=32 time=2ms TTL=64
Reply from 172.18.4.194: bytes=32 time<1ms TTL=128
Reply from 172.18.4.195: bytes=32 time=2ms TTL=64
Reply from 172.18.4.197: bytes=32 time=1ms TTL=255
Reply from 172.18.4.198: bytes=32 time=2ms TTL=128
Reply from 172.18.4.199: bytes=32 time=2ms TTL=128
Reply from 172.18.4.200: bytes=32 time=1ms TTL=128
Reply from 172.18.4.204: bytes=32 time<1ms TTL=128
Reply from 172.18.4.206: bytes=32 time=1ms TTL=128
Reply from 172.18.4.214: bytes=32 time<1ms TTL=128
Reply from 172.18.4.221: bytes=32 time<1ms TTL=128
Reply from 172.18.4.223: bytes=32 time<1ms TTL=128
Reply from 172.18.4.233: bytes=32 time=1ms TTL=128
Reply from 172.18.4.238: bytes=32 time=1ms TTL=128
Reply from 172.18.4.241: bytes=32 time<1ms TTL=128
Reply from 172.18.4.244: bytes=32 time=6ms TTL=64
Reply from 172.18.4.248: bytes=32 time=1ms TTL=128
0
 
Harper McDonaldCommented:
In PowerShell:

For ($i=1;172..254;$i++) {

ping.exe -n 1 ("172.18.4." + $i) | where{$_ -match "bytes=32"}

}

Open in new window


Results:

PS C:\> .\ping.ps1
Reply from 172.18.4.25: bytes=32 time=6ms TTL=64
Reply from 172.18.4.35: bytes=32 time=2ms TTL=64
Reply from 172.18.4.36: bytes=32 time=1ms TTL=64
Reply from 172.18.4.43: bytes=32 time<1ms TTL=128
0
 
dsterlingAuthor Commented:
So the 254 would be a /24 subnet and for a /25 it would be 128, but what about the second half of the subnet for the /25?

Thank you,
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
dsterlingAuthor Commented:
Great, thank you
0
 
Harper McDonaldCommented:
Cool glad to help!
0
 
Harper McDonaldCommented:
There are also freeware tools from SolarWinds that can help you with what you are trying to do..
0
 
Steve KnightIT ConsultancyCommented:
BTW in a batch can just do a loop.  For command line use %a, if in batch file you use an extra % to make %%a.  You can get fancier but most basic this will loop %a from 1 to 254:

for /l %a in (1,1,254) do @ping 192.168.1.%a -n 1 -w 50

Useful when you only have basic stuff available to find what is online.

(for /l %a in (1,1,254) do @ping 192.168.1.%a -n 1 -w 50) > ping.txt
arp -a >> ping.txt
start ping.txt

etc.

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.