Quickly Ping A Range of IP to Find Dead IP on Windows

PowerShell

Instead of looking for a tool, there is a very quick and easy way that lets me ping a wild range of IPs to find out which IPs are free and which ones have been taken, using the PowerShell built-in cmdlet Test-Connection.

And here is how:

$iprange = 200..254
Foreach ($ip in $iprange)
{
    $computer = "192.168.37.$ip"
    $status = Test-Connection $computer -count 1 -Quiet
    if (!$status)
    {
        $computer + " - available" 
    }
}
image 15 - Quickly Ping A Range of IP to Find Dead IP on Windows

Copy the code over to PowerShell ISE console, change the IP info and hit the green Go button. You will get the result within a minute.

I personally really like this block of code because I can run many other things between each IP loop to gather more information about each computer on the network, such as uptime, hard drive usage, etc. But if you prefer a one-liner that gives you a set of simple result, try this.

200..254 | foreach { $status=Test-Connection "192.168.37.$_" -Count 1 -Quiet; "192.168.37.$_ $status"}

Hope it helps.

4 thoughts on “Quickly Ping A Range of IP to Find Dead IP on Windows

  1. Simple solution, I like it. Very easy to expand the one liner to multiple subnets as well! Thanks heaps for the post!

    Also, I did a test with Test-Connection and using the Ping class directly on the same network and subnet and the ping class directly seem to be quite a lot quicker.
    Test-Connection TotalMinutes: 17.550881065
    Ping Class TotalMinutes: 3.81168999

    A version of the final one liner I ended up using:
    0..254 | foreach { $i = $_; 1..254 | foreach{ $isOnline = (New-Object System.Net.NetworkInformation.Ping).Send(“192.168.$i.$_”, 1000); “192.168.$i.$_`: $($isOnline.Status)” }}

    Thanks for the post!

Leave a Reply

Your email address will not be published.