时间:2023-02-22 08:21:01 | 来源:建站知识
时间:2023-02-22 08:21:01 来源:建站知识
Ipv6 DDNS(阿里云域名解析及证书配置):curl -sL --connect-timeout 3 "tdns.cupker.cn/d?dn=$aliddnsipv6_name&type=AAAA"curl -sL --connect-timeout 3 "119.29.29.29/d?dn=$aliddnsipv6_name&type=AAAA"
``# 模拟命令行# 但是最新的标准已经更新为了:$()更加简单和一堵
#!/bin/sh#The script is best to run with bash. The command format is bash aliddns#Change your Ali AK in the quotation marks belowaliddnsipv6_ak="AccessKey ID"#Change your Alibaba SK in the quotation marks below. To put it bluntly, these are the account and passwordaliddnsipv6_sk="Access Key Secret"#Change the following quotation marks into the prefix of the domain name you want to resolve. If it is the root domain name, fill in it directly@aliddnsipv6_name1="area" #Change the following quotation marks to the main domain name you want to resolve, for example: baidu comaliddnsipv6_domain="domain.cn"#Change the parsing switching time you need in the quotation marks below. Alibaba defaults to a maximum of 600 seconds, which can be reduced by spending moneyaliddnsipv6_ttl="600"#Judge whether it contains @ because the resolution containing @ is directly reported to xxx COM, instead of blindly reporting as @ xxx. comif [ "$aliddnsipv6_name1" = "@" ]then aliddnsipv6_name=$aliddnsipv6_domainelse aliddnsipv6_name=$aliddnsipv6_name1.$aliddnsipv6_domainfi#Make time and record good momentsecho "Now Time:$(date)"#Here are two ways to get the IPv6 address of your local machine, so that one can hang up and the other can be backed up. Of course, you can also use the if statement to judge. If the first one doesn't work, use the second...#If you want to resolve IPv4, put the following v6 ident. Replace me with v4 ident. me#v6.ident. If me fails, switch to IPv6 directly ip. sb# ipv6=`curl -sL --connect-timeout 3 v6.ident.me` # if [ "$ipv6" = "" ]# then# ipv6=$(ip -o addr show |grep -v deprecated|grep ' inet6 [^f:]'|sed -nr 's#^.+? +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#/2 /1#p'|grep 'ff:fe'|sort -nr|head -n1|cut -d' ' -f2)# Print out the current local IPv6 address. What did you do to compare the programecho "LocalHost IP:$ipv6"#The following is to get the IPv6 address currently resolved by Alibaba for you. If you want to resolve IPv4, replace AAAA with a########It is recommended to use the default one, because after you update DNS, dns9 hichina. COM is effective immediately#########To resolve IPv4, you need to delete &type=AAA#current_ipv6=`nslookup -query=AAAA $aliddnsipv6_name dns9.hichina.com 2>&1 | grep 'Address: ' | tail -n1 | awk '{print $NF}'`current_ipv6=$(curl -sL --connect-timeout 3 "tdns.cupker.cn/d?dn=$aliddnsipv6_name&type=AAAA")# tdns.cupker.cn bind tdns.cupker.cn#$(ip -o addr show |grep -v deprecated|grep ' inet6 [^f:]'|sed -nr 's#^.+? +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#/2 /1#p'|grep 'ff:fe'|sort -nr|head -n1|cut -d' ' -f2)# $(curl -sL --connect-timeout 3 "119.29.29.29/d?dn=$aliddnsipv6_name&type=AAAA")#Print it again for you to see clearly echo "Current Alibaba resolution ip:$current_ipv6"#If the local IPv6 and Alibaba resolve the same, I'll passif [ "$ipv6" = "$current_ipv6" ] then echo "You see, the IP hasn't changed and doesn't need to be updated. I'm leaving..." exit#If it's different, I'll start updating itelse unset aliddnsipv6_record_idfi#The timestamp format should be correcttimestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")#The following are Alibaba related, all of which are required in various formats, as well as obtaining recordid and so on. Let's jump to the update record and go downurlencode() { # urlencode <string> out="" while read -n1 c do case $c in [a-zA-Z0-9._-]) out="$out$c" ;; *) out="$out$(printf '%%%02X' "'$c")" ;; esac done echo -n $out}enc() { echo -n "$1" | urlencode}send_request() { local args="AccessKeyId=$aliddnsipv6_ak&Action=$1&Format=json&$2&Version=2015-01-09" local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddnsipv6_sk&" -binary | openssl base64) curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"}get_recordid() { grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'}#Here ----------- the following type=aaaa is the only difference between updating IPv6 and IPv4. The rest of the update codes are the same, so it can be understood in this way -- line feed#For example, the following can be changed from AAAA to aquery_recordid() { send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddnsipv6_name&Timestamp=$timestamp&Type=AAAA"}update_record() { send_request "UpdateDomainRecord" "RR=$aliddnsipv6_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"}add_record() { send_request "AddDomainRecord&DomainName=$aliddnsipv6_domain" "RR=$aliddnsipv6_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"}if [ "$aliddnsipv6_record_id" = "" ]then aliddnsipv6_record_id=$(query_recordid | get_recordid) fiif [ "$aliddnsipv6_record_id" = "" ]then aliddnsipv6_record_id=$(add_record | get_recordid) echo "New parsing has been added$aliddnsipv6_name $ipv6 $aliddnsipv6_record_id"else update_record $aliddnsipv6_record_id echo "New parsing has been added $aliddnsipv6_name as $ipv6" fi
#!/bin/ship addr show|grep -A1 'inet [^f:]'|sed -nr 's#^ +inet ([0-9.]+)/[0-9]+ brd [0-9./]+ scope global .*#/1#p'ip addr show|grep -v deprecated|grep -A1 'inet6 [^f:]'|grep -v ^--|sed -nr ':a;N;s#^ +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#/2 /1#p;Ta'|grep 'ff:fe'|sort -nr|head -n1|cut -d' ' -f2
显示ipv6的脚本执行步骤是,#!/bin/ship -o addr show|grep 'inet [^f:]'|sed -nr 's#.+? +inet ([0-9.]+)/[0-9]+ brd [0-9./]+ scope global .*#/1#p'ip -o addr show |grep -v deprecated|grep ' inet6 [^f:]'|sed -nr 's#^.+? +inet6 ([a-f0-9:]+)/.+? scope global .*? valid_lft ([0-9]+sec) .*#/2 /1#p'|grep 'ff:fe'|sort -nr|head -n1|cut -d' ' -f2
关键词:证书,配置