简体   繁体   中英

How to check which Azure Resource is using the specific IP address?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM