Reputation: 1141
I'd like to know which Azure resources is using the specific IP address that I input like below:
$IP = Read-Host -Prompt "Enter The IP Address to search"
If ([ipaddress]::TryParse($IP,[ref][ipaddress]::Loopback)) {
Write-Host "IP address $($IP)" -ForegroundColor Yellow
# Find any Azure resource that is using this IP address as input
} Else {
Exit
}
I know that there are some scripts that can be used to find but it only showing for IP that is used by the VM, not by anything else.
in this case the IP address that I am looking for 110.13.28.80 is associated with my ExpressRoute circuit.
Upvotes: 1
Views: 20034
Reputation: 116
Here are a couple ways I found for private IP address. The simple one works well for VMs and Private Endpoints, but I wasn't able to find Gateway addresses. The second method goes through each VNet and is able to find more IPs like for Gateways.
I also noticed that this is "per-subscription", so we need to do Select-AzSubscription
each to check each seperate subscription.
$IP = '10.11.12.13'
$NICs | Where-Object {$_.IpConfigurations.PrivateIpAddress -like $IP } |
FL Name, VirtualMachine, @{N="Subnet";E={$_.IpConfigurations.Subnet.Id}}
Here is the other way by going through each VNet...
$IP = '10.11.12.13'
$VNet = Get-AzVirtualNetwork | Get-AzVirtualNetwork -ExpandResource 'subnets/ipConfigurations' |
Where-Object {$_.Subnets.IpConfigurations.PrivateIpAddress -eq $IP }
$Subnet = $VNet.Subnets | Where-Object {$_.IpConfigurations.PrivateIpAddress -eq $IP }
$NIC = $Subnet.IpConfigurations | Where-Object {$_.PrivateIpAddress -eq $IP }
$Result = [PSCustomObject]@{
"VNet Name" = $VNet.Name
"VNet Address Prefix" = $VNet.AddressSpace.AddressPrefixes
"Subnet Name" = $Subnet.Name
"Subnet Address Prefix"= $Subnet.AddressPrefix
"NIC Name" = $NIC.Name
"NIC IP" = $NIC.PrivateIpAddress
}
$Result | FT
Upvotes: 3
Reputation: 31454
You can get the public IP with filter the IP address, and then you can see the IP configuration, it will show you which resource it is used by:
Get-AzPublicIpAddress | Where-Object IpAddress -eq 'ipAddress'
The example IP configuration shows here:
This example shows the public IP is used by a network interface.
Upvotes: 3