Where Can I Live? What Address is Available?

Probably, most of us have shopped for a new place to live at some time in our life. Regardless of the type of place we wanted to buy (i.e. home versus condo), the first thing we needed to know was what addresses or properties were available. And we basically had two options: either ask a realtor what places are available or find them ourselves (i.e. search the internet or drive around our desired neighborhood).

In a similar sense, sometimes when we are working with SQL Server, we need an (IP) address. We may need this address when we are building a windows cluster or when we are adding a listener for an Availability Group.

So, the question becomes how do we go about finding what is available? Well, we can ask someone on the infrastructure team what IP address is available or we could find one ourselves. This latter option is what I am going to demonstrate in this post using PowerShell.

PowerShell code to examine a certain IP range and resolve the host names

 The code is based around GetHostEntry (https://msdn.microsoft.com/en-us/library/ms143997.aspx), which will query a DNS server for the IP address that is associated with a host name or IP address.

$ip_address_base = "123.456.789."

# address parameters: $i is start, $j is ending

$i = 1

$j = 32

while ($i -lt $j){

$ip_address = $ip_address_base + $I


trap{$ip_address; continue}

$i = $i + 1


So, with this simple piece of code, you can very quickly find what IP addresses appear to be available. However, even when I use this code, I still normally ask the infrastructure team if I could use a certain address. The reason I do this is because they may have a design to where things should be or certain addresses reserved for reasons I don’t know about.

This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s