Last update at :2024-07-08,Edit by888u
Due to the needs of the project, some friends need to periodically use Cloudflare to manage a large number of domain names and websites for domain name and site DNS management. Today, a netizen found Snail and asked if there was a simpler and batch way to add domain names in batches. For example, he needs more than a hundred domain names to add and delete every month. If the operation can be automated and batched, it will save a lot of money. Big time.
Cloudflare actually provides an API, and you can use its function to add domain names in batches. In this article, Snail will try to see how to solve this problem.
First, preparations
1. Have a Cloudflare account
2. Linux or native MacOS that needs to execute the script
3. Apply for Cloudflare API key (My Profile-Global API Key)
4. Use a .txt document to record the domain name list with one line per line, such as domain.txt
Second, use API to add domain names in batches
1. Execute API
export CF_API_EMAIL=Our CF account email export CF_API_KEY=API application key
2. Editing cycle
for domain in $(cat domain.txt); do \\\\curl -X POST -H \\”X-Auth-Key: $CF_API_KEY\\” -H \\”X-Auth-Email: $CF_API_EMAIL\\” \\\\-H \\”Content-Type: application/json\\” \\\\\\”https://api.cloudflare.com/client/v4/zones\\” \ \\\–data \\\'{\\”name\\”:\\”\\'$domain\\'\\”,\\”jump_start\\”:true}\\'; done p>
3. Feedback information
Then we saw that Snail added several domain names to domain.txt and executed the addition process. The above snail made a speculative move and randomly found a few unregistered domain names, which cannot be added. It seems to be relatively strict.
Here I found several common and normally registered domain names to add in. Of course, I do not have permission to add them. I just gave an example to illustrate that only registered domain names can be added, otherwise no errors will be reported.
Third, modify DNS
We cannot modify the domain name DNS in batches. If our domain name is registered with a registrar, we can also modify the DNS in batches. Just modify it directly to Cloudflare's DNS.
To summarize, through the Cloudflare API we can quickly add domain names to CF accounts in batches. Because manual addition requires a period of time for each domain name to be detected, batching can improve efficiency, especially for those who need a large number of domain names.
Recommended site search: independent IP virtual host, virtual host ranking, registered website, Hong Kong high-defense server rental, private server rental, US server rental, Hong Kong proxy server Hong Kong high-defense server, website query domain name entrance, Korean server recommendation,
发表评论