Skip to content

Instantly share code, notes, and snippets.

@mitaken
Last active December 25, 2016 07:12
Show Gist options
  • Save mitaken/2ce86e7e9358524454ed to your computer and use it in GitHub Desktop.
Save mitaken/2ce86e7e9358524454ed to your computer and use it in GitHub Desktop.
Aterm Router Reboot
Option Explicit
Const CstStrDomain = "http://192.168.179.1"
Const CstStrReboot = "/index.cgi/reboot_main"
Const CstStrRebootSet = "/index.cgi/reboot_main_set"
Dim ObjHttp, StrBody
Set ObjHttp = WScript.CreateObject("Msxml2.XMLHTTP.6.0")
On Error Resume Next
'SESSION IDを取得する
Call ObjHttp.open("GET", CstStrDomain & CstStrReboot, False)
Call ObjHttp.send()
If Err.Number <> 0 Then
Call MsgBox(Err.Description,, "エラー")
WScript.Quit
End If
While ObjHttp.readyState <> 4
Wend
StrBody = ObjHttp.responseText
Dim ObjReg, ObjMatches, StrSession
Set ObjReg = New RegExp
ObjReg.Pattern = "'([0-9A-F]{32})'"
Set ObjMatches = ObjReg.Execute(StrBody)
If ObjMatches.Count <> 1 Then
Call MsgBox("SESSION_ID取得に失敗",, "エラー")
Call WScript.Quit(ObjMatches.Count)
End If
StrSession = ObjMatches(0).Submatches(0)
Set ObjMatches = Nothing
Set ObjReg = Nothing
'再起動実行
Call ObjHttp.open("POST", CstStrDomain & CstStrRebootSet, False)
Call ObjHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call ObjHttp.send("SESSION_ID=" & StrSession)
If Err.Number <> 0 Then
Call MsgBox(Err.Description,, "エラー")
Call WScript.Quit(Err.Number)
End If
While ObjHttp.readyState <> 4
Wend
StrBody = ObjHttp.responseText
If InStr(StrBody, "/reboot_main_finish") = 0 Then
Call MsgBox("再起動失敗",, "エラー")
Call WScript.Quit(ObjHttp.status)
End If
Set ObjHttp = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment