PowerShell Kieran Jacobsen PowerShell Kieran Jacobsen

Azure China Region support for AzurePublicIPAddresses

Photo courtesy of Microsoft. https://azure.microsoft.com/en-us/regions/

Photo courtesy of Microsoft. https://azure.microsoft.com/en-us/regions/

I am happy to announce version 0.8.1 of Azure Public IP Addresses PowerShell module.

With this release, the module now supports the China North and China East Azure regions.

Microsoft’s China Azure regions are operated by 21Vianet, Microsoft publishes the IP subnets for these regions in a separate file to the other regions, Windows Azure Datacenter IP Ranges in China.

To implement this functionality, some changes have been made to the module. Important Note: these changes do not break any existing functionality and should not impact existing code.

Get-MicrosoftAzureDatacenterIPRangeFile

The switch parameter, -ChinaRegion has been added to the Get-MicrosoftAzureDatacenterIPRangeFile CMDLet. When this parameter is specified, the then China region specific file will be downloaded; if it is absent, then it will download the general region file.

Additional validation has been added to the -Path parameter. Invalid paths should no longer be accepted.

Get-MicrosoftAzureDatacenterIPRange

This function has been to support the China North and China East Regions much like adding any other region.

Changes were required for the -path parameter. When this parameter is absent, both files are automatically downloaded. When -path is present, the CMDLet will now inspect the file spectified, and generate a warning that some Azure regions will be unavailable.

One additional change has been made to this CMDLet. The -AzureRegion parameter will now accept an array containing regions. I have also added additional validation to this parameter to ensure invalid data is not passed in (via [ValidateNotNullOrEmpty()]).

I have attempted to quite throughly test the changes to this CMDLet using Pester, and have expanded the number of included tests to ensure there are no changes.

Getting the module

The module is available via the PowerShell Gallery and GitHub.

Missing Regions

Unfortunately, there is still no support for the following regions:

  • US Gov Texas
  • US Gov Virginia
  • US DoD Central
  • US DoD East
  • Germany Northeast
  • Germany Central

These regions are not included in either of the region files, nor are they in their own region. If and when they are available, I will include support for them.

It should also be noted that currently the UK West region is missing from the Microsoft Azure Datacenter IP Ranges file. I have reached out to Azure support to resolve this.

Read More
PowerShell Kieran Jacobsen PowerShell Kieran Jacobsen

How Big Is That Subnet?

I recently had a long list of IPv4 CIDR addresses and wanted to know how many hosts there were in total. Looking at the list, there was a mix of common sizes, /29, /24 and /16 but there were a few I just don’t know off the top of my head. The list was long, and it would have be tedious work manually calculating each.

Get-SubnetSize

So, I did what any IT professional in my shoes would do, I wrote some code. The Get-SubnetSize CMDLet will return the total number of usable (often referred to as the number of host) addresses for a specified subnet.

By default, it doesn't count the subnet ID or the broadcast addresses, however, there is a switch -IncludeSubnetIDAndBroadcastAddress, to include those if need them included.

Working with Get-SubnetSize

To work out the size of the subnet 172.16.0.0/24, we simply call: Get-SubnetSize -CIDR 172.16.0.0/24 which will return 254.

Get-SubnetSize -CIDR ’172.16.0.0/24’

Get-SubnetSize -CIDR ’172.16.0.0/24’

What about if we had a subnet mask? Well we can work that out as well! How big is 255.0.0.0? Get-SubnetSize -Subnetmask 255.0.0.0 returns 16777214.

Get-SubnetSize -Subnetmask '255.0.0.0'

Get-SubnetSize -Subnetmask '255.0.0.0'

How many public IP addresses does Azure use?

Previously I have written about my AzurePublicIPAddresses module in my post, Working with Azure’s public IP addresses. This module allows you to obtain the public IP addresses available in each Azure Region. The module is updated for each new Azure Region that Microsoft introduces.

Combining Get-MicrosoftAzureDatacenterIPRange, Get-SubnetSize and Measure-Object together, we can create a one-liner that will give us the total number of subnets and IP addresses.

Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum
Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum

Get-MicrosoftAzureDatacenterIPRange | Select-Object -ExpandProperty Subnet | Get-SubnetSize | Measure-Object -Sum

And we can see that there are 2621 Subnets and a whopping 7,613,174 IP addresses!!

Getting the module

Posh-SubnetTools is available from the PowerShell Gallery or from the project’s GitHub page.

This module should work with all versions of PowerShell, including PowerShell Core. I have tested the module on PowerShell 5.1 (Windows 10 Insiders).

I appreciate any issues, pull requests or comments that you may have. Have an idea for a new CMDLet, make a pull request and I will include it!

Read More
PowerShell Kieran Jacobsen PowerShell Kieran Jacobsen

Working with Azure’s public IP addresses

If you have spent much time working with Microsoft Azure, Amazon AWS or any public cloud provider, you have probably started to wonder about how many public IPv4 addresses they have. Whilst we know there is a limit to the number of addresses, and that we have reached these limits, it still seems like there are quite a few to go around.

I recently had the need to get a listing of all the Azure subnets, and whilst I did this, I thought it would be good to make a reusable PowerShell module to assist.

Microsoft makes this process pretty easy, providing an XML file under the Microsoft Download Center title: Microsoft Azure Datacenter IP Ranges. There are a few things to note about this file:

  • It contains all compute (including SQL),
  • It is updated on Wednesday (Pacific Time), but changes are effective from the following Monday (Pacific Time), and,
  • The file will contain only production Azure DCs, for instance, at the time of writing the German and Canadian DCs are not contained in the file.

I have developed a PowerShell module that simplifies working with this file by developing CMDLets that:

  1. Allowing for automated downloads of the file, and,
  2. Allow for specific DCs to be extracted

Get-MicrosoftAzureDatacenterIPRangeFile provides us with a method to simply and easily access the XML document. If called without parameters, we will get the XML document returned, however we can opt to save the file to disk for future processing.

Then we have Get-MicrosoftAzureDatacenterIPRange. With this CMDLet, we can get a list of objects containing the subnets (in CIDR format) for a specific DC or for all of the DCs. You can specify the path to a previously downloaded file, or it can download the file for us (and keep it in memory).

The module can be found on:

I have tested this module against PowerShell 5, however there should be no issue with earlier versions (I recommend PowerShell 3 or higher). If you encounter any issues, please raise an issue on the GitHub page.

Just in case you were wondering, Azure has approximately 1700 subnets, or around 5.8 million IPv4 addresses!

Kieran Jacobsen

Read More