花生壳Oray动态域名自动更新IP

前言:由于最近家里公网IP经常变动,自己又有个Oray的域名,所以想弄个动态IP更新上去,而Oray的花生壳服务现在要花钱(还限制端口),所以已经不考虑花生壳了

一、Oray设置

进入域名设置的 其他服务-自主管理,开启自主管理设置

二、关键URL API

1.登录

首先需要获取到登录token

def getToken():
    headers={
        "Authorization":"",
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    url="http://dm-api.oray.com/authorization" #登录url
    ret=requests.post(url,data='{"rootname": "自主管理域名", "password": "密码"}',headers=headers) #data是raw格式
    _json=json.loads(ret.text)
    return _json['token']

2.获取recordid

def getRecordItem ():
    url="http://dm-api.oray.com/resolves/自助管理根域名"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    ret=requests.get(url,headers=headers)
    _json=json.loads(ret.text)
    for _item in _json:
        if(_item['name']=='你目标二级域名头'):
            return _item
recordid=getRecordItem()['recordid']

3.更新IP

def updateIp():
    url="http://dm-api.oray.com/resolves/你要修改的二级域名"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    _json=json.loads('{"recordid":1,"domainname":"你要修改的二级域名","subname":"二级域名头","line":0,"recordtype":"a","value":"","ttl":3600,"priority":0}')
    _json['value']=ip #你要提交的ip
    _json['recordid']=getRecordItem()
    _data=json.dumps(_json)
    requests.post(url,data=_data,headers=headers)

以上就完成了,根据自己使用的不同语言进行http调用修改就行,放一份完整的Python代码仅供参考(假设要修改的二级域名:nas.example.cn)

import json
import requests
ip="127.0.0.1"
def getToken():
    headers={
        "Authorization":"",
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    url="http://dm-api.oray.com/authorization"
    post=requests.post(url,data='{"rootname": "example.cn", "password": "123456"}',headers=headers)
    _json=json.loads(post.text)
    return _json['token']
token=getToken()
def getRecordItem():
    url="http://dm-api.oray.com/resolves/example.cn"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    ret=requests.get(url,headers=headers)
    _json=json.loads(ret.text)
    for _item in _json:
        if(_item['name']=='nas'):
            return _item
def updateIp():
    url="http://dm-api.oray.com/resolves/nas.example.cn"
    headers={
        "Authorization":"Bearer {0}".format(token),
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "Host":"dm-api.oray.com",
        "Origin":"http://diy.oray.com",
        "Referer":"http://diy.oray.com/domain",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
    }
    _json=json.loads('{"recordid":0,"domainname":"nas.example.cn","subname":"nas","line":0,"recordtype":"a","value":"","ttl":3600,"priority":0}')
    _json['value']=ip
    _json['recordid']=getRecordItem()['recordid']
    _data=json.dumps(_json)
    requests.post(url,data=_data,headers=headers)
updateIp()

发表评论

电子邮件地址不会被公开。