GoDaddy 動態設定對應IP

在沒有固定IP的情況下,利用shell script 定時更新GoDaddy上面網址的對應IP。

以下將使用 Synology NAS 設定

登入後,進入控制台/任務排程表

新增/排程任務/使用者定義指令碼

輸入相關資訊,並以root權限執行

並在“使用者定義指令碼”中輸入

#!/bin/bash
# This script checks and automatically updates your GoDaddy DNS "A" record server with your current IP address.
# by Marius Bogdan Lixandru updated to make it work with Synology NAS for users with Dynamic IP.
domain="quantoyo.com"   # Your own domain name
name="這邊是要修改的name"     # name of A record to update
key="這邊是從GoDaddy取得的key"     # Your own GoDaddy developer API Key See STEP 4
secret="這邊是從GoDaddy取得的secret"   # Your own GoDaddy developer API Secret Key See STEP 4

headers="Authorization: sso-key $key:$secret"

# echo $headers

result=$(curl -s -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/A/$name")

#echo $result;

dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
#echo "dnsIp:" $dnsIp

# Get public IP address. There are several websites that can do this.
ret=$(curl -s GET "https://ipinfo.io/json")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")


#echo "currentIp:" $currentIp

if [ "$dnsIp" != "$currentIp" ];
 then
#	echo "Ips are not equal"
	request='[{"data":"'$currentIp'","ttl":600}]'
#	echo " request:" $request
	nresult=$(curl -i -s -X PUT \
 -H "$headers" \
 -H "Content-Type: application/json" \
 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
#	echo "result:" $nresult
fi

接下來是到GoDaddy取得上述資訊的方法

Step1. 進入GoDaddy 開發者頁面並登入

https://developer.godaddy.com/keys

點擊Create Key

輸入name 並選擇production

取得 key 與secret 後,跟上面指定的name 三個資訊填入上面的程式碼中即可自動更新IP

參考資料:

https://mariushosting.com/synology-how-to-automatically-update-godaddy-a-record-if-you-have-dynamic-ip/


更新: GoDaddy 已經取消該API 對於小用戶的支援,當帳號內的domain低於50 個將被阻擋使用此API,並收到以下訊息

{"code":"ACCESS_DENIED","message":"Authenticated user is not allowed access"}

這是Reddit 上網友詢問官方的回應,不得不說Godaddy 非常不友善呢…

I had the same issue. Emailed API support. This is the response I get.

" Hi,

Thank you for reaching out to us regarding the recent changes to our Domain API.

We wanted to inform you that we have recently updated our Domain API requirements. As part of this update, customers are now required to have 50 or more domains in their account to utilize the API. Unfortunately, as you currently only have 1 domain in your account, access to the API is blocked for you.

However, we want to assure you that you still have access to the OTE API without any blocks.

We apologize for any confusion or inconvenience this may have caused. If you have any further questions or need assistance with any other aspect of our services, please don't hesitate to reach out.

Thank you for your understanding.

Regards,

API Support Team"

參考資料:https://www.reddit.com/r/godaddy/comments/1bl0f5r/am_i_the_only_one_who_cant_use_the_api/

發佈留言