Last active
December 22, 2020 14:53
-
-
Save Feng-Zihao/847ecb482e75fe045637abfe377d95f9 to your computer and use it in GitHub Desktop.
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 | |
# 请自行获取下列4个变量 | |
# TOKEN由 “安全中心 - 用户管理” 获取,格式为 ID,TOKEN | |
# DOMAIN_ID、RECORD_ID 可以从DNSPod控制台的AJAX记录JSON返回值获取 | |
# SUB_DOMAIN 自行填写 | |
LOGIN_TOKEN= | |
DOMAIN_ID= | |
RECORD_ID= | |
SUB_DOMAIN= | |
# get current record on dnspod | |
RESP=`curl -s -X POST https://dnsapi.cn/Record.Info -d "login_token=$LOGIN_TOKEN&format=json&domain_id=$DOMAIN_ID&record_id=$RECORD_ID"` | |
# echo "$RESP" | |
CURRENT_RECORD_VALUE=`echo -n $RESP | grep "\"value\":\"[^\"]*\"" -Eo | grep "[0-9.]+" -Eo` | |
echo "CURRENT RECORD VALUE $CURRENT_RECORD_VALUE" | |
# get current record on device | |
# 从pppoe-wan接口获取 | |
# CURRENT_IP=`ifconfig pppoe-wan | grep "inet addr:[^ ]+" -Eo | grep "[0-9.]+" -Eo` | |
# 从 3322.org 获取 | |
CURRENT_IP=`curl -s http://members.3322.org/dyndns/getip` | |
echo "CURRENT_IP $CURRENT_IP" | |
if [ "$CURRENT_IP" != "$CURRENT_RECORD_VALUE" ]; then | |
echo "update record" | |
curl -X POST https://dnsapi.cn/Record.Modify -d "login_token=$LOGIN_TOKEN&format=json&domain_id=$DOMAIN_ID&record_id=$RECORD_ID&sub_domain=$SUB_DOMAIN&value=$CURRENT_IP&record_type=A&record_line=默认" | |
else | |
echo "don't need update" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment