作成 2013.04.06
更新 2013.04.06
DDNS を更新する (XGJ.JP編)
Windows で xgj.jp を更新する用。コード中の HOST_NAME と PASSWORD の設定を変更する。
実行結果はイベントログの Application ログに記録される。
ddns-xgj-update.wsf
<job id="ddns update job">
<comment>DDNS Update for xgj.jp</comment>
<object id="WshShell" progid="WScript.Shell" />
<object id="objIE" progid="InternetExplorer.Application" />
<object id="adoStream" progid="ADODB.Stream" />
<script language="JScript">
function encodeBody(str){return encodeURIComponent(str);}
</script>
<script language="VBScript">
Option Explicit

Const HOST_NAME = "hostname"
Const PASSWORD = "password"
Const TIMEOUT = 10
Const UPDATE_URL = "https://www.xgj.jp/ddns_mod.php"
Const HEADER_OPTION = "Content-type: application/x-www-form-urlencoded"
Const evError = 1
Const evInfo = 4

Dim postData,countdown,resultText
adoStream.Open
adoStream.Charset = "Shift_JIS"
adoStream.WriteText "host=" & encodeBody(HOST_NAME) & "&pass=" & encodeBody(PASSWORD)
adoStream.Position = 0
adoStream.Type = 1
postData = adoStream.Read
adoStream.Close

objIE.Navigate UPDATE_URL,,,postData,HEADER_OPTION & vbCrLf

countdown = TIMEOUT * 2
Do While objIE.Busy Or objIE.readystate <> 4
  WScript.Sleep 500
  countdown = countdown - 1
  If countdown <= 0 Then Exit Do
Loop

If countdown <= 0 Then
  WshShell.LogEvent evError, REMOTE_CHECK & " Timeout."
Else
  resultText = objIE.Document.body.innerText
  If Left(resultText,1) = "O" Then
    WshShell.LogEvent evInfo,resultText
  Else
    WshShell.LogEvent evError,resultText
  End If
End If
objIE.Quit
</script>
</job>
タグ: DNS WSF

©2004-2017 UPKEN IPv4