Finding Public IP Details
I was recently asked how to query Azure Resource Graph to find details about what a public ip is associated to.
The goal is to see the different types of resources public ips are associated like:
- VMs
- Scalesets
- Bastion hosts
- gateways
- etc
- not associated.
After playing around with the query language and discovering that it doesn’t implement the entire language, no let
keyword, I came up with the following:
resources
| where type =~ 'Microsoft.Network/publicIPAddresses'
| project
id,
joinId = iff(isempty(properties.ipConfiguration.id), '', tolower(strcat('/', strcat_array(array_slice(split(properties.ipConfiguration.id,'/'), 1, -3), '/')))),
orphaned = iff(isempty(properties.ipConfiguration.id), true, false),
pubipname = name,
resourceGroup,
ipAddress = properties.ipAddress
| extend _provider = iff(orphaned, dynamic([{}]), split(split(joinId, 'providers')[1], '/'))
| extend associated_to_provider = iif(orphaned, '', strcat_delim('/',_provider[1], _provider[2]))
| join kind=leftouter(
resources
| project id = tolower(id), name
) on $left.joinId == $right.id
| project
id, name = pubipname, ipAddress, orphaned, associated_to_name = name, associated_to_provider, associated_to_id = joinId
This creates a result of:
ID | NAME | IPADDRESS | ORPHANED | ASSOCIATED_TO_NAME | ASSOCIATED_TO_PROVIDER | ASSOCIATED_TO_ID |
---|---|---|---|---|---|---|
/subscriptions/ |
SyslogAgent-ip | null | 0 | syslogagent126 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
SyslogAgent2-ip | null | 0 | SyslogAgent2-nic | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
sentinelagent1-ip | null | 0 | sentinelagent1-nic | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
Telegraf-InfluxDB-Grafana-ip | 104.210.56.85 | 0 | telegraf-influxdb-gr68 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
PowerBIReports-ip | null | 0 | powerbireports726 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
bastionHosts | 192.168.17.43 | 0 | blxBillingvnet425-bastion | microsoft.network/bastionhosts | /subscriptions/ |
/subscriptions/ |
confluence | 192.168.17.45 | 0 | confluence768 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
confluence-app-ip | 192.168.17.4 | 0 | confluence-app991 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
confluence-database | null | 0 | confluence-database729 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
Ubuntu2-ip | null | 0 | ubuntu2105 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
aerotest-ip | null | 0 | aerotest635 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
blxlogtest-ip | null | 0 | blxlogtest803 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
buildmachine-ip | null | 0 | buildmachine966 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
development-vnet-ip | 192.168.17.5 | 0 | development-vnet-bastion | microsoft.network/bastionhosts | /subscriptions/ |
/subscriptions/ |
devpubip | 192.168.17.100 | 0 | devgateway | microsoft.network/virtualnetworkgateways | /subscriptions/ |
/subscriptions/ |
homeassistant-ip | null | 0 | homeassistant92 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
mongodb-ip | 192.168.17.200 | 1 | |||
/subscriptions/ |
mytestpolicyvm-ip | null | 0 | mytestpolicyvm172 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
myubuntu-ip | null | 0 | myubuntu718 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
ubuntu-pip | 192.168.17.201 | 0 | ubuntu194 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
ubuntu1704-ip | null | 0 | ubuntu1704435 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
ubuntu17102-ip | null | 0 | ubuntu17102672 | microsoft.network/networkinterfaces | /subscriptions/ |
/subscriptions/ |
kafka-vm-ip | 192.168.17.204 | 1 | |||
/subscriptions/ |
testkafka-ip | null | 0 | testkafka258 | microsoft.network/networkinterfaces | /subscriptions/ |