赞
踩
本笔记将记录:使用腾讯的 API 进行更改域名解析的方法。实现在 IP 地址发生变化的时候,调用接口修改域名的 DNS 解析。
腾讯的接口地址:https://cloud.tencent.com/document/api/302/8511
不过我调用的时候返回了403,提了工单,他们家说目前出于封闭状态,让我等待进一步确认。emmmmm.....那就等等把。
# 08/02/2018 好了已经,具体原因不想说了。客观的讲:(1)没有仔细看文档;(2)不能说我们没有仔细看,只能说腾讯把完整的 URL 放在“示例”里。
生成接口参数的时候你可能需要用到 SHA1 算法来签名,如果你在 SHELL 中可能会用到 OpenSSL 的如下命令:
# echo -n "value" | openssl dgst -sha1 -hmac "key" 57443a4c052350a44638835d64fd66822f813319 # echo -n "value" | openssl sha1 -hmac "key" 57443a4c052350a44638835d64fd66822f813319
上面的两个命令是等价的。参数“key”是腾讯的SecretKey,文档已描述如何获取;参数“value”是要签名的原串。
使用命令 curl(1) 发送请求,下面是 SHELL 脚本的关键部分:
#!/bin/sh IPADDRESS="// 要解析的IP地址" SecretId="// 参见文档" SecretKey="// 参见文档" domain="// k4nz.com" recordId="// 记录ID,直接去腾讯云平台复制就行了" subDomain="// 子域" recordType="A" recordLine="默认" METHOD="GET" PROTOCOL='https://' HOST='cns.api.qcloud.com' URI='/v2/index.php' PARAM="Action=RecordModify&Nonce=${RANDOM}&SecretId=${SecretId}&Timestamp=$(date +%s)&domain=${domain}&recordId=${recordId}&recordLine=${recordLine}&recordType=${recordType}&subDomain=${subDomain}&value=${IPADDRESS}" signString="${METHOD}${HOST}${URI}?${PARAM}" signature=$(echo -n "$signString" | openssl dgst -sha1 -hmac "${SecretKey}" -binary | base64) requestUrlWithoutSignature=${PROTOCOL}${HOST}${URI}?${PARAM} curl -G -s "$requestUrlWithoutSignature" --data-urlencode "Signature=$signature"
选项 --data-encode 来编码签名
选项 -X 控制请求方式
#!/bin/sh set -e # 缓存文件 cache_file="/tmp/$(basename $0).tmp" touch $cache_file echo -e "cache_file:\t${cache_file}" # 获取出口网卡的网络地址 interface=$(ip --json --pretty route list default | jq --raw-output '.[0].dev') echo -e "interface:\t$interface" ip_address=$(ip --json address | jq --raw-output '.[] | select( .ifname == "'${interface}'" ) | .addr_info | .[] | select( .family == "inet" ) | .local') echo -e "ip_address:\t$ip_address" # 检测网络地址是否发生变化 previous_ip_address=$(cat $cache_file) echo -e "prev_address:\t${previous_ip_address}" if [ "$ip_address" == "$previous_ip_address" ] then exit 0 else echo -n $ip_address > $cache_file fi # 设置动态域名解析参数 IPADDRESS="${ip_address}" SecretId="<SecretId>" SecretKey="<SecretKey>" domain="k4nz.com" recordId="407218721" subDomain="example" recordType="A" recordLine="默认" # 发送请求设置域名解析 METHOD="GET" PROTOCOL='https://' HOST='cns.api.qcloud.com' URI='/v2/index.php' # ? PARAM="Action=RecordModify&Nonce=${RANDOM}&SecretId=${SecretId}&Timestamp=$(date +%s)&domain=${domain}&recordId=${recordId}&recordLine=${recordLine}&recordType=${recordType}&subDomain=${subDomain}&value=${IPADDRESS}" signString="${METHOD}${HOST}${URI}?${PARAM}" signature=$(echo -n "$signString" | openssl dgst -sha1 -hmac "${SecretKey}" -binary | base64) requestUrlWithoutSignature=${PROTOCOL}${HOST}${URI}?${PARAM} echo -e "http_response:\t"$(curl -G -s "$requestUrlWithoutSignature" --data-urlencode "Signature=$signature")
「BIND9」- DLZ(Dynamically Loadable Zones)
HMAC-SHA1 in bash
HTTP POST and GET using cURL in Linux
Any way to encode the url in curl command?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。