Hello everyone and have a nice day!
Gentlemen, how to massively change all IP addresses of all type A records in all domains within an account?
Change IP addresses in all sites - this topic offers a script that replaces the IP address of records of type A only within one zone_id, within one domain.
But what if I have 100+ domains on my account and all of them have the same IP address of the A record, which needs to be replaced with another one in all domains?
You can just add another loop to go through all zones in your account.
To solve my question, it was enough to “glue” two scripts:
- replacement of IP addresses for all records of type A within one zone_id: Change IP addresses in all sites
- view all zone_id in the account we need How to get zone id for all domains - #3 by gnirola
And as result is a working script:
#!/bin/bash
auth_email="[email protected]"
auth_key="123qaz"
zone_id_list=( $(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/?per_page=500" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json"| jq -r '.result[].id') )
for zone_id in "${zone_id_list[@]}"
do
record_list=( $(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records?per_page=500&type=A&content=111.111.111.111" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | jq -r '.result[].id') )
for id in "${record_list[@]}"
do
curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${id}" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data '{"content":"222.222.222.222"}'
done
done
Tested and works on fedora-33/centOS. With a high degree of probability, it will be necessary to deliver the package:
sudo dnf install jq -y
and 