Question

This would be easy for you. Maybe not for me...

I just need to reboot my modem from a script. I'm trying to do it the same way I use to reboot my router. This is emulating HTTP headers with the following script and executing it from Windows Script Host (wscript):

URL_Submit="http://192.168.100.1/goform/gscan";
ContentTypeSubmit="application/x-www-form-urlencoded";
ContentLengthSubmit="24";
POSTDATASubmit="SADownStartingFrequency=";

var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");

function send(URL_POST,CT,CL,CD)
{  
  WinHttpReq.open("POST", URL_POST, true);
  WinHttpReq.SetRequestHeader("Content-Type", CT);
  WinHttpReq.SetRequestHeader("Content-Length", CL);
  WinHttpReq.send(CD);
};

function Submit()
{
    send(URL_Submit,ContentTypeSubmit,ContentLengthSubmit,POSTDATASubmit)
};

Submit();

A similar script works for my router but this one is not working for my modem. The regular way I actually use for rebooting my modem is from its admin panel, submitting the following form:

<html>
   ...
<body>
   ... 
<form action="http://192.168.100.1/goform/gscan" method="POST">
<input name="SADownStartingFrequency"> <input value="Click here to restart" type="submit">
</form>
   ...
</body>
</html>

Note: form may be submitted in blank. It isn't mandatory to fill it in.

What would it be a correct way to emulate this form submission using any ECMAScript implementation to be able to execute it from Windows Script Host?

Thanks in advance for your time.

Denik.

EDIT:

I found a way to do this as follow:

var doc = new ActiveXObject("htmlfile");
var form = doc.createElement("form");
var input = doc.createElement("input");

form.name = "gscan";
form.method = "POST";
form.action = "http://192.168.100.1/goform/gscan";

input.type = "text";
input.name = "SADownStartingFrequency";

doc.appendChild(form);
form.appendChild(input);

form.submit();

But I still have the problem that everytime I submit the form, an Internet Explorer window is opened and, as I said in my question, I need the script to be run on Windows Script Host, without opened windows. I want to run it at the background.

If anyone knows any other way, please let me know. Thanks.

Was it helpful?

Solution

This is a way I found to do it. It works well for me:

'modem_reboot.vbs
'For Cisco DPC2203 Modem rebooting

dim Browser
set Browser = WScript.CreateObject("InternetExplorer.Application")
Browser.Visible = false
Browser.Navigate "about:blank"
Browser.Document.Body.InnerHTML = _
"<form name=""reboot"" action=""http://192.168.100.1/goform/gscan"" method=""POST"">" + _
"<input name=""SADownStartingFrequency""> <input value=""Click here to restart"" type=""submit"">" + _
"</form>"

Browser.Document.reboot.Submit()

WScript.Sleep 5000

Browser.Quit
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top