百度智能云解析DNS python版api ddns实现2023最新

发现之前有网友发的过期了
写的也很不好用。
百度智能云解析DNS python版api ddns实现2023-12最新

import hmac
import time
import requests 

#把*****星号改成自己的就行了

host="dns.baidubce.com"
yourdomin="****.com" 
AK='*******************************'
SK="*******************************"
url=f"/v1/dns/zone/{yourdomin}/record"

def getheaders(method,url):
    utc=time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())
    quoteutc=utc.replace(":","%3A")
    key=hmac.new(SK.encode(),f"bce-auth-v1/{AK}/{utc}/1800".encode(),digestmod="SHA256").hexdigest()
    message=f"""{method}\n{url}\n\nhost:{host}\nx-bce-date:{quoteutc}"""
    signature=hmac.new(key.encode(),message.encode(),digestmod="SHA256").hexdigest()
    Authorization=f"bce-auth-v1/{AK}/{utc}/1800/host;x-bce-date/"+signature

    headers={
        "x-bce-date":utc,
        'Authorization':Authorization
    }
    return headers

def 查询():
    headers=getheaders("GET",url)
    res=requests.get(f"http://{host}"+url,headers=headers).json()
    print(res)
    return res

def 添加(ip):
    cids=查询()
    cid=cids.get("records")[0]["id"]
    headers=getheaders("PUT",url+"/"+cid)
    data={
        "rr":"@",
        "type":"AAAA",
        "value":ip,
        "ttl": 300
    }
    res=requests.put(f"http://{host}"+url+"/"+cid,json=data,headers=headers).text
    print(res)
    return res
def getipv6():
    return '0000:0000:7c0:cb17:a000:0000:fe50:6cc2'


添加(getipv6())

#接口地址:https://cloud.baidu.com/doc/DNS/s/El4s7lssr

【禁止转载】

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值