I am trying to get a list of Public IP addresses that are not associated to any azure resource. That is 'orphaned public ip addresses'. I want to know if Azure public IP is 'associated' via Python SDK.
Using the below SDK:
from azure.mgmt.network import NetworkManagementClient
network_client = NetworkManagementClient(credential, SUBSCRIPTION_ID)
public_ip_list = network_client.public_ip_addresses.list_all()
Iterating over 'public_ip_list' will give me all the details regarding IP, but it wont say if it is 'associated' with any azure resource or not.
You can use the below to get both associated and non-associated Public IPs with Azure service using Azure python sdk.
You can get the public IP that is not associated with Azure resource when you set ip_config to none and also you can get the count of both associated and non-associated IP.
Code:
Sample Output:
Reference:
Public IP Addresses - List All - REST API (Azure Virtual Networks) | Microsoft Learn