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" 
    }
}

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.

5 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!

  2. if (!$status)
    {
    $computer + ” – available”
    }
    else
    {
    $computer + ” – not available”
    }

    will give you “both” available and not available, i know it’s simple to infer not available from the list of available but if you’re exporting for a report it would be cleaner for the list to not have gaps. like if you’re trying to find a contiguous block it’ll be easier to pick one out of the list if everything is in there.

Leave a Reply

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