Skip to content

Instantly share code, notes, and snippets.

@maskati
Created November 28, 2023 05:59
Show Gist options
  • Save maskati/ab33d3e02ef28e098065f7d19326e16e to your computer and use it in GitHub Desktop.
Save maskati/ab33d3e02ef28e098065f7d19326e16e to your computer and use it in GitHub Desktop.
Check which Azure service tag network prefixes contain a specific IP address

Run with PowerShell 7.4 or later based on .NET 8 which includes the new IPNetwork type. Requires authenticated Azure CLI.

# e.g. ns-sb2-prod-am3-002.cloudapp.net (service bus namespace in westeurope)
$ip=[net.ipaddress]::parse("104.46.32.56")

az network list-service-tags --location westeurope | `
  convertfrom-json | `
  select -exp values -pv st | `
  %{$_.properties.addressprefixes | `
    %{[pscustomobject]@{Name=$st.name;AddressPrefix=$_}}
  } | `
  ?{[net.ipnetwork]::parse($_.addressprefix).contains($ip)} | `
  ft -auto

Example result for 104.46.32.56 resolved from A record ns-sb2-prod-am3-002.cloudapp.net for Service Bus namespace in West Europe. This result shows that as of November 2023 Azure service tags are incorrect, since the IP address should be included in ServiceBus.WestEurope, but it is only included in the more general AzureCloud and related EventHub service tags.

Name                  AddressPrefix
----                  -------------
AzureCloud            104.46.32.0/19
AzureCloud.westeurope 104.46.32.0/19
EventHub              104.46.32.56/32
EventHub.WestEurope   104.46.32.56/32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment