Skip to content

Instantly share code, notes, and snippets.

@HouCoder
Last active June 9, 2021 22:25
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HouCoder/bd9b5b1542e5baa5b75be35b5e80a3fd to your computer and use it in GitHub Desktop.
Save HouCoder/bd9b5b1542e5baa5b75be35b5e80a3fd to your computer and use it in GitHub Desktop.
Godaddy DNS record updater.
#!/bin/bash
# https://developer.godaddy.com/keys
KEY=""
SECRET=""
domain="example.com"
name="a-record"
# Get public IP from ipinfo.io
public_ip="$(curl --silent ipinfo.io/ip)"
# get current record
current_record="$(dig @8.8.8.8 +short $name.$domain)"
if [ "$current_record" != "$public_ip" ]; then
echo New public IP is $public_ip
# Update godaddy A record - https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName
curl -X PUT "https://api.godaddy.com/v1/domains/$domain/records/A/$name" \
-H "Authorization: sso-key $KEY:$SECRET" \
-H 'Content-Type: application/json' \
--data '[{"type": "A", "name": "'"$name"'", "data": "'"$public_ip"'", "ttl": 3600}]'
else
echo Nothing changed
fi
@onefen123
Copy link

onefen123 commented Feb 20, 2019

我用的是centos7提示:line 22: syntax error near unexpected token `fi'
并且我打印echo $current_record打印不出值,有没联系方式教我一下我的q3006139

@jy02239285
Copy link

路由器运行sh
错误提示
[Router /home/id]# ./godaddy_ddns.sh
New public IP is 100.11.xx.xx
curl: (51) Cert verify failed: BADCERT_NOT_TRUSTED
如果我使用跳过
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
则提示

syntax error: unexpected word (expecting ")")

头疼,暂时还没看到godaddy更新ip.

@HouCoder
Copy link
Author

HouCoder commented Jan 6, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment