How to use PowerShell to restart router?
My computer is connected to the router using a network cable, the router acts as a modem, it connects to the ISP through PPPoE, my computer is behind NAT.
The model of my router: Huawei HS8545M, LAN address: 192.168.1.1, webpage administrator login: CMCCAdmin, webpage administrator password: aDm8H%MdA.
I have to do the following to restart the router (7 clicks in total, the browser remembers the login and password):
Way too many steps.
I have tried to use this method:
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Navigate "https://192.168.1.1"
But after a short while the connection is lost, .Document
is empty, trying to refresh results in this error:
OperationStopped: The RPC server is unavailable. (0x800706BA)
I am using Windows 10 20H2 and I have disabled Remote Desktop, Remote Assistance, Remote Registry, Windows Remote Management and many other things, I disabled remote stuff because they pose threats to security, I think they are relevant to this; By the way, RPC
service is running.
Can anyone help me?
Source code of first page: page1.html
Source code of second page: page2.html
This should be simple to do, login in 192.168.1.1, create a cookie, and use the cookie to get into 192.168.1.1/index.asp, submit Restart_button, job done, however I am not very familiar with commands that deal with networks...
I am currently looking for the Python way, I am using Python 3.9.1 amd64, I have put it in PATH long ago, I have installed Selenium and Twill via pip. and downloaded and extracted GeckoDriver.exe to Python installation folder;
I know selenium, twill, urllib, urllib2, cookielib and webbot, all are capable of doing this, I am currently trying to figure out how to do it in the best way.
I have managed to login to the router in Python via twill, however I don't know what to do next:
from twill.commands import *
go('http://192.168.1.1')
showforms()
fv("1","txt_Username","CMCCAdmin")
fv("1","txt_Password","aDm8H%MdA")
showforms()
submit('btnSubmit')
go("http://192.168.1.1/index.asp")
The button:
<input type="button" name="Restart_button" id="Restart_button" class="submit" style="width:98px" onclick="Reboot()" value="重启">
It is located at:
html.body.#container.#center.#content.table.tbody.tr.td.#frameContent.html.body.div.#Restart_button
Also, the inputfields
of the first page(http://192.168.1.1):
PS C:\Windows\System32> $html.inputfields
outerHTML : <input name="txt_Username" type="text" id="txt_Username" style="float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;" maxlength="31"/>
tagName : INPUT
name : txt_Username
type : text
id : txt_Username
style : float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;
maxlength : 31
outerHTML : <input name="txt_Password" type="password" id="txt_Password" maxlength="127" style="float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;"
maxlength="31"/>
tagName : INPUT
name : txt_Password
type : password
id : txt_Password
maxlength : 31
style : float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;
outerHTML : <input type="button" id="btnSubmit" name="btnSubmit" value="确定" onclick="SubmitForm();" class="button_css"/>
tagName : INPUT
type : button
id : btnSubmit
name : btnSubmit
value : 确定
onclick : SubmitForm();
class : button_css
outerHTML : <input type="reset" name="Submit2" value="取消" onclick="canceltext();" class="button_css"/>
tagName : INPUT
type : reset
name : Submit2
value : 取消
onclick : canceltext();
class : button_css
I have got the source code of the reset page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<link rel="stylesheet" href='../../../../Cuscss/frame.css?2020070716413845-1425773353' type='text/css'>
<script language="JavaScript" src="../../../resource/common/util.js?2020070716413845-1425773353"></script>
<script language="JavaScript" type="text/javascript">
function LoadFrame()
{
}
function Reboot()
{
if(ConfirmEx("确定要重启设备吗?"))
{
setDisable('Restart_button', 1);
setDisable('Restore_button', 1);
setDisable('btnRestoreDftCfg', 1);
var Form = new webSubmitForm();
Form.setAction('set.cgi?x=' + 'InternetGatewayDevice.X_HW_DEBUG.SMP.DM.ResetBoard'
+ '&RequestFile=html/ssmp/devmanage/cmccdevicereset.asp');
Form.addParameter('x.X_HW_Token', getValue('onttoken'));
Form.submit();
}
}
</script>
</head>
<body class="mainbody" onLoad="LoadFrame();">
<div class="func_spread"></div>
<div class="title_with_desc">
<label id="Title_reboot_lable">设备重启</label>
</div>
<div class="title_01" style="padding-left:10px;" width="100%">
<label id="Title_reboot_tips_lable">点击如下按钮重启路由器。</label>
</div>
<div class="button_spread"></div>
<div align="right">
<input type="hidden" name="onttoken" id="hwonttoken" value="de0f5f98c4d4a77239ccb981cd5c4bf3">
<input type='button' name="Restart_button" id="Restart_button" class="submit" style="width:98px" onClick='Reboot()' value="重启">
</div>
</body>
</html>
It is located at address:
http://192.168.1.1/html/ssmp/devmanage/cmccdevicereset.asp
Also I don't really know if Submit('btnSubmit')
logged me in or not, I am not totally sure...
And although this works, Firefox initializes very slowly.
I have finally figured out how to do it the telnet way:
telnet 192.168.1.1
root
adminHW
reset
How can I make it a script that automatically inputs commands?