北京联通宽带打电话跟联通申请了公网ip,想跟自己的域名进行绑定,但是公网ip在重新拨号后会变化,所以写了如下脚本自动更改公网ip
感谢dragon2k的博客,添加到crontab中即可
腾讯云DNS解析api地址 https://cloud.tencent.com/document/product/302/4032
#!/bin/bash domain='你的域名,例如qq.com' subDomain='你希望解析的子域名,例如www.qq.com,则只输入www,腾讯云域名解析列表中的主机记录' sId='你的云API秘钥SecretId' sKey='你的云API秘钥SecretKey' function getId(){ signatureMethod='HmacSHA1' timestamp=`date +%s` nonce=`head -200 /dev/urandom | cksum | cut -f2 -d" "` region=bj url="https://cns.api.qcloud.com/v2/index.php" #获取域名解析条目ID:recordId action='RecordList' recordType='A' src=`printf "GETcns.api.qcloud.com/v2/index.php?Action=%s&Nonce=%s&Region=%s&SecretId=%s&SignatureMethod=%s&Timestamp=%s&domain=%s&recordType=A&subDomain=%s" $action $nonce $region $sId $signatureMethod $timestamp $domain $subDomain` #echo 'src: ' $src signature=`echo -n $src|openssl dgst -sha1 -hmac $sKey -binary |base64` #echo 'signature: ' $signature params=`printf "Action=%s&domain=%s&Nonce=%s&Region=%s&SecretId=%s&Signature=%s&SignatureMethod=%s&Timestamp=%s&recordType=A&subDomain=%s" $action $domain $nonce $region $sId "$signature" $signatureMethod $timestamp $subDomain` #echo 'params: ' $params msg=`curl -G -d "$params" --data-urlencode "Signature=$signature" "$url"` #1:获取records数组 #2:获取id #echo $msg|jq '.data.records[]'|grep -B 11 -A 3 'type\": \"A\"'|grep -A 6 -B 8 'name\": \"www\"'|jq .id #echo $msg|jq '.data.records[]'|grep -B 11 -A 4 'type\": \"A\"'|jq .id echo $msg|jq '.data.records[]'|jq .id } #获取recordId recordId=$(getId) function updateMyDomainIP(){ signatureMethod='HmacSHA1' timestamp=`date +%s` nonce=`head -200 /dev/urandom | cksum | cut -f2 -d" "` region=bj url="https://cns.api.qcloud.com/v2/index.php" #获取ip #ip=`curl http://2019.ip138.com/ic.asp >/dev/null|iconv -fgb2312 -t utf-8 |sed 's/.*\[\(.*\)\].*/\1/g'` #获取自己的公网ip ip=`curl https://api.myip.com|jq .ip|sed 's/\"//g'` action='RecordModify' recordType='A' recordLine='默认' value=$ip timestamp=`date +%s` nonce=`head -200 /dev/urandom | cksum | cut -f2 -d" "` src=`printf "GETcns.api.qcloud.com/v2/index.php?Action=%s&Nonce=%s&Region=%s&SecretId=%s&SignatureMethod=%s&Timestamp=%s&domain=%s&recordId=%s&recordLine=%s&recordType=%s&subDomain=%s&value=%s" $action $nonce $region $sId $signatureMethod $timestamp $domain $recordId $recordLine $recordType $subDomain $value` echo 'src: ' $src signature=`echo -n $src|openssl dgst -sha1 -hmac $sKey -binary |base64` #echo 'signature: ' $signature params=`printf "Action=%s&Nonce=%s&Region=%s&SecretId=%s&SignatureMethod=%s&Timestamp=%s&domain=%s&recordId=%s&recordLine=%s&recordType=%s&subDomain=%s&value=%s" $action $nonce $region $sId $signatureMethod $timestamp $domain $recordId $recordLine $recordType $subDomain $value` echo 'params: ' $params curl -G -d "$params" --data-urlencode "Signature=$signature" "$url" } #执行 updateMyDomainIP
原文链接:https://blog.csdn.net/chenguihua5/article/details/105776391
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END