skyline_z skyline_z - 1 year ago 117
Python Question

Is there any python API which can get the IP address (internal or external) of Virtual machine in Azure

I want to control the VMs in Azure with python SDK. Is there any API that can get a VM's IP address (internal or external) according to VM's name?

Answer Source

Based on my understanding, I think you want to get the public & private ip addresses of a Azure VM using Azure SDK for Python.

For getting these ip addresses (internal & external), please see the code below.

from import NetworkManagementClient, NetworkManagementClientConfiguration

subscription_id = '33333333-3333-3333-3333-333333333333'

credentials = ...

network_client = NetworkManagementClient(

VM_NAME = 'xxx'

public_ip_address = network_client.public_ip_addresses.get(GROUP_NAME, PUBLIC_IP_NAME)

As reference, you can refer to the documents below to know the details of the code above.

  1. Resource Management Authentication using Python for the variable credentials.
  2. Create the management client for the variable network_client.
  3. More details for the package, please see
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download