kk_lee69 发表于 2022-8-12 08:08:22

如何使用AUTOIT 更新 GODADDY DNS? 有人可以协助改写吗??[已解決]

本帖最后由 kk_lee69 于 2022-8-12 15:54 编辑

想利用AUTOIT 更新 GODADDY DNS 可惜网上原本有这样的一个项目 现在却没有程序了
https://github.com/saulofg/GoDaddyDNS
找了其他的 确只找到 PowerShell 跟 BASH的范例语法
https://www.instructables.com/Quick-and-Dirty-Dynamic-DNS-Using-GoDaddy/
可惜这都不是我所能够了解的…..所以只好上来询问 看看有无高手可以协助 改写成 AUTOIT的语法的$mydomain = "sos-obx.us"
$myhostname = "gateway"
$gdapikey = "api_key:key_secret"

$myip = Invoke-RestMethod -Uri "https://api.ipify.org"
$dnsdata = Invoke-RestMethod "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" }
$gdip = $dnsdata.data
Write-Output "$(Get-Date -Format 'u') - Current External IP is $($myip), GoDaddy DNS IP is $($gdip)"

If ( $gpid -ne $myip) {
Write-Output "IP has changed!! Updating on GoDaddy"
Invoke-RestMethod -Method PUT -Uri "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" } -ContentType "application/json" -Body "[{`"data`": `"$($myip)`"}]";
}

zghwelcome 发表于 2022-8-12 08:49:50

前2条HTTP协议的GET命令
最后执行判断后,执行一个PUT命令

kk_lee69 发表于 2022-8-12 09:05:11

本帖最后由 kk_lee69 于 2022-8-12 09:07 编辑

zghwelcome 发表于 2022-8-12 08:49
前2条HTTP协议的GET命令
最后执行判断后,执行一个PUT命令
高手 可否寫個範例?? 我看不懂 譬如 -Headers這個位置要放什麼??

zghwelcome 发表于 2022-8-12 09:49:37

$oHTTP.setRequestHeader('Authorization', 'sso-key xxxxxxxxxxxxx')
xxxxxxxxxxxxxxxxx   是你的key

kk_lee69 发表于 2022-8-12 10:09:09

zghwelcome 发表于 2022-8-12 09:49
$oHTTP.setRequestHeader('Authorization', 'sso-key xxxxxxxxxxxxx')
xxxxxxxxxxxxxxxxx   是你的key
不好意思 可以請教一下嗎??

$url = "https://api.ipify.org"
$httpObj = ObjCreate("winhttp.winhttprequest.5.1")
$httpObj.open("GET", $url)
$httpObj.Send()
$HTMLSource = $httpObj.ResponseBody
ConsoleWrite($HTMLSource&@CRLF)

我想先做第一個GET應該是獲取 IP   但是我的程式卻出現 $httpObj.Send()看訊息應該是 $httpObj = ObjCreate("winhttp.winhttprequest.5.1")
這個沒成功

我的電腦WIN7這個是不是有支援度的問題 或者版本問題我需要先安裝什麼嗎??

zghwelcome 发表于 2022-8-12 10:24:00

看不懂你遇到了什么问题
ConsoleWrite(BinaryToString($HTMLSource) & @CRLF)

kk_lee69 发表于 2022-8-12 10:56:58

本帖最后由 kk_lee69 于 2022-8-12 11:06 编辑

zghwelcome 发表于 2022-8-12 10:24
看不懂你遇到了什么问题
ConsoleWrite(BinaryToString($HTMLSource) & @CRLF)


>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\暫存區\AUTOIT程式\鼎新 產品基本檔案輸入\WinHttp_GetRespond\DDNS.au3"   
D:\???\AUTOIT??\?? ????????\WinHttp_GetRespond\DDNS.au3 (28) : ==> The requested action with this object has failed.:
$httpObj.Send()
$httpObj.Send()^ ERROR
>Exit code: 1    Time: 1.855

---------------------------------------------------------------------
ObjCreate("winhttp.winhttprequest.5.1")
這個是不是有支援度的問題 或者版本問題我需要先安裝什麼嗎?? 我的電腦WIN7


zghwelcome 发表于 2022-8-12 11:06:36



该网站启用了TLS协议,win7需要安装补丁,安装方法baidu 或 google一下
win10 系统无需安装协议

zghwelcome 发表于 2022-8-12 11:06:52



该网站启用了TLS协议,win7需要安装补丁,安装方法baidu 或 google一下
win10 系统无需安装协议

kk_lee69 发表于 2022-8-12 11:31:53

zghwelcome 发表于 2022-8-12 11:06
该网站启用了TLS协议,win7需要安装补丁,安装方法baidu 或 google一下
win10 系统无需安装协议

OK我用WIN10 正常了不過
$dnsdata = Invoke-RestMethod "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" }

這個我就不知道怎麼改了
$url = "https://api.godaddy.com/v1/domains/"&$mydomain&"/records/A/"&$myhostname&" -Headers @{ Authorization = "&$gdapikey&" } "

這樣好像也無法通過.....

zghwelcome 发表于 2022-8-12 11:55:53

$mydomain = "sos-obx.us"
$myhostname = "gateway"
$gdapikey = "api_key:key_secret"

$url = "https://api.godaddy.com/v1/domains/" & $mydomain & "/records/A/" & $myhostname
$httpObj = ObjCreate("winhttp.winhttprequest.5.1")
$httpObj.open("GET", $url)
$httpObj.setRequestHeader('Authorization', 'sso-key ' & $gdapikey)
$httpObj.Send()
$HTMLSource = $httpObj.ResponseBody
ConsoleWrite(BinaryToString($HTMLSource) & @CRLF)

kk_lee69 发表于 2022-8-12 13:36:31

zghwelcome 发表于 2022-8-12 11:55
$mydomain = "sos-obx.us"
$myhostname = "gateway"
$gdapikey = "api_key:key_secret"


OK太感謝了   只剩下PUT

Invoke-RestMethod -Method PUT -Uri "https://api.godaddy.com/v1/domains/$($mydomain)/records/A/$($myhostname)" -Headers @{ Authorization = "sso-key $($gdapikey)" } -ContentType "application/json" -Body "[{`"data`": `"$($myip)`"}]";

-Headers已經知道怎麼處理還再找 -ContentType跟 -Body 的範例

不知道 是否 可以教學一下 感謝

zghwelcome 发表于 2022-8-12 13:37:53

论坛一大堆范例,随便找找看

kk_lee69 发表于 2022-8-12 14:01:57

zghwelcome 发表于 2022-8-12 13:37
论坛一大堆范例,随便找找看

$url = "https://api.godaddy.com/v1/domains/" & $mydomain & "/records/A/" & $myhostname
$httpObj = ObjCreate("winhttp.winhttprequest.5.1")
$httpObj.open("PUT", $url)
$httpObj.setRequestHeader('Authorization', 'sso-key ' & $gdapikey)
$httpObj.setRequestHeader('ContentType', 'application/json ' )
;$httpObj.setRequestHeader('Body', '[{"data": "32.5.5.5"}]' )
$httpObj.Send('[{"data":"211.2.2.2","name":"video","ttl":600,"type":"A"}]')
$HTMLSource = $httpObj.ResponseBody
ConsoleWrite(BinaryToString($HTMLSource) & @CRLF)


>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\User\Desktop\DDNS.au3"   
{"code":415,"message":"unsupported media type \"text/plain\", only are allowed"}
>Exit code: 0    Time: 0.562


我看過 $httpObj.setRequestHeader('ContentType', 'application/json ' ) 這個寫法但是 找不到 Body有看過好像 有人把要送出的資料 放在SEND()確得到錯誤訊息

zghwelcome 发表于 2022-8-12 15:03:40

把两边的中括号去了试试[ ]
页: [1] 2
查看完整版本: 如何使用AUTOIT 更新 GODADDY DNS? 有人可以协助改写吗??[已解決]