1、申请godaddy api
这个可以自己google,链接在这里:
https://developer.godaddy.com/keys
2、查询需要的customerId
使用godaddy需要三个东西,除了申请的api_key和api_secret之外还需要customerId,查看自己的customerId的方式:
这是官方提供的方法
https://developer.godaddy.com/doc/endpoint/shoppers#/v1/get
curl -X 'GET' \
'https://api.godaddy.com/v1/shoppers/shopperId?includes=customerId' \
-H 'accept: application/json' \
-H 'Authorization: sso-key api_key:api_secret'
将上面shopperId替换为你的godaddy账号id,一般为10个数字的,也就是客户编号
api_key api_secret
上面这两个也要替换成你自己的,查询正确之后会返回这样的一串字符串
{"shopperId":"8888888888","marketId":"zh-SG","email":"曹操@gmail.com","externalId":null,"nameFirst":"操","nameLast":"曹","customerId":"23184dj-7yhed-23dsa-212rwef43-234e3w"}
只需要最后的customerId即可
3、修改nameserver
import requests
# godaddy的api
api_key = 'api_key'
api_secret = 'api_secret'
# customerid需要使用用户id单独获取
customerid = 'customerid'
# 修改godaddy域名的nameserver
def edit_ns(domain):
# 设置请求头
godaddy_headers = {
'Authorization': f'sso-key {api_key}:{api_secret}',
'accept': 'application/json',
'Content-Type': 'application/json'
}
godapi = f'https://api.godaddy.com/v2/customers/{customerid}/domains/{domain}/nameServers'
# 先从cf获取域名的ns,ns的值是个包含2个元素的列表,['ns1.com', 'ns2.com']
newns = {
'nameServers': ['ns1.com', 'ns2.com']
}
respones = requests.put(godapi, json=newns, headers=godaddy_headers)
if respones.status_code == 202:
print('修改成功')
return True
else:
print('修改失败')
return False
# 修改nameserver值
edit_ns('google.com')