PowerShell : Find-AvailableIP

I use NMAP frequently and there are many times that I wish to have its functions on different environments. In this case I was interested in finding how many IP were available for capacity on a local network, knowing that all devices on my network have ICMP enabled.

Using NMAP

In this article I’ve used NMAP to get a list of all IP on my network:

My first idea was use Python and Python-nmap library, but I think that PowerShell using Test-Connection or ping was simple and good enough, especially if we run it on powershell core this will work on every os.

Using PowerShell

Using the ping command is a simple way to leverage ICMP protocol and check if a host is reachable. Test-Connection is essentially the same command, so we can specify some parameters to speed up the process (e.g. limit to just one attempt). Whenever we are starting an interactive script that can take some time to complete, I like to use Write-Progess to provide a meaningful information about the progress and the status at runtime.
I’ve added a Write-Verbose to add some more information about the number of the results that can sometime be required.

This is the output

Remember to use the Dot-Sourcing before calling the Find-AvailableIP function.

Let’s view the code

You can find this script, as usual, on my github repo.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.