Created
October 8, 2018 14:50
-
-
Save athurg/8b49971888c338ba0b1f259a4fb0d834 to your computer and use it in GitHub Desktop.
用于OpenWRT的腾讯云DNS自动更新脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Howto | |
# 1. Install pkgs by run `opkg install ca-bundle openssl-util libustream-openssl` | |
# 1. Upload this script to your OpenWRT router. | |
# 2. Save as /etc/hotplug.d/iface/99-ddns. | |
# 3. Replace the VARIABLES below. | |
# 4. Enjoy! | |
# variables should be changed | |
DOMAIN="yourname.com" | |
RECORD_ID=123456789 | |
SUB_DOMAIN="home" | |
SECID="YOUR_SECRET_ID" | |
SECKEY="YOUR_SECRET_KEY" | |
###################### DO NOT CHANGE ANYTHING BELOW ###################### | |
[ "$ACTION" = ifup ] || exit 0 | |
[ "$INTERFACE" = wan ] || exit 0 | |
ip=$(ifconfig pppoe-wan | grep inet | awk '{print $2}' | cut -c 6-) | |
TIMESTAMP=$(date +%s) | |
# Construct the query with MANUAL order, DO NOT REORDER THEM | |
QUERY="Action=RecordModify" | |
QUERY="${QUERY}&Nonce=${TIMESTAMP}" | |
QUERY="${QUERY}&SecretId=${SECID}" | |
QUERY="${QUERY}&Timestamp=${TIMESTAMP}" | |
QUERY="${QUERY}&domain=${DOMAIN}" | |
QUERY="${QUERY}&recordId=${RECORD_ID}" | |
QUERY="${QUERY}&recordLine=默认" | |
QUERY="${QUERY}&recordType=A" | |
QUERY="${QUERY}&subDomain=${SUB_DOMAIN}" | |
QUERY="${QUERY}&value=${ip}" | |
# Generate signature | |
STR="POSTcns.api.qcloud.com/v2/index.php?${QUERY//_/.}" | |
# hexdump and sed are URLEncode hack | |
SIGNATURE=$(echo -n "${STR}" | openssl sha1 -binary -hmac "${SECKEY}" | openssl base64 | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g') | |
wget --post-data="${QUERY}&Signature=${SIGNATURE}" -O - https://cns.api.qcloud.com/v2/index.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment