写一个阿里云DDNS Linux脚本
时间: 2023-02-25 20:06:29 浏览: 139
好的,以下是一个阿里云DDNS的Linux脚本:
```
#!/bin/bash
# 阿里云DDNS脚本
# 请替换以下变量
AK="your_access_key_id"
SK="your_access_key_secret"
DomainName="your_domain_name"
RR="your_RR"
# 获取公网IP
IP=`curl -s http://ipecho.net/plain`
# 获取当前DNS记录
RecordId=`curl -s http://alidns.aliyuncs.com/?Action=DescribeSubDomainRecords&AccessKeyId=$AK&SignatureMethod=HMAC-SHA1&SignatureNonce=$RANDOM&SignatureVersion=1.0&Timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")&Version=2015-01-09&Signature=$(echo -n "GET&%2F&AccessKeyId%3D$AK%26Action%3DDescribeSubDomainRecords%26DomainName%3D$DomainName%26RRKeyWord%3D$RR%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D$RANDOM%26SignatureVersion%3D1.0%26Timestamp%3D$(date -u "+%Y-%m-%dT%H:%M:%SZ")%26Version%3D2015-01-09" | openssl sha1 -hmac "$SK&" -binary | base64)`
RecordId=`echo $RecordId | awk -F '"' '/RecordId/{print $4}'`
# 判断DNS记录是否存在,如果存在则更新,否则创建
if [ "$RecordId" != "" ]; then
curl http://alidns.aliyuncs.com/?Action=UpdateDomainRecord&AccessKeyId=$AK&SignatureMethod=HMAC-SHA1&SignatureNonce=$RANDOM&SignatureVersion=1.0&Timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")&Version=2015-01-09&RecordId=$RecordId&RR=$RR&Type=A&Value=$IP&Signature=$(echo -n "GET&%2F&AccessKeyId%3D$AK%26Action%3DUpdateDomainRecord%26DomainName%3D$DomainName%26RR%3D$RR%26RecordId%3D$RecordId%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D$RANDOM%26SignatureVersion%3D1.0%26Timestamp%3D$(date -u "+%Y-%m-%dT%H:%M:%SZ")%26Type%3DA%26Value%3
阅读全文