Update Azure DNS Records with Python: A Step-by-Step Guide
To update an Azure DNS record using Python, follow these steps:
- Install the Azure SDK for Python using pip:
pip install azure-mgmt-dns
- Authenticate with your Azure account and create a DNS client:
from azure.identity import DefaultAzureCredential
from azure.mgmt.dns import DnsManagementClient
from azure.mgmt.dns.models import RecordSet
credential = DefaultAzureCredential()
dns_client = DnsManagementClient(credential, subscription_id)
- Get the current record set:
resource_group_name = 'my-resource-group'
zone_name = 'my-zone.com'
record_type = 'A'
record_set_name = 'www'
record_set = dns_client.record_sets.get(resource_group_name, zone_name, record_type, record_set_name)
- Update the record set:
ttl = 3600
ip_address = '192.168.1.1'
new_record_set = RecordSet(ttl=ttl, arecords=[{'ipv4_address': ip_address}])
dns_client.record_sets.create_or_update(resource_group_name, zone_name, record_type, record_set_name, new_record_set)
This will update the 'www' A record in the 'my-zone.com' zone to point to the IP address '192.168.1.1' with a TTL of 3600 seconds.
原文地址: http://www.cveoy.top/t/topic/oFTV 著作权归作者所有。请勿转载和采集!