Xeн*_*вϵς 5 networking router powershell python windows-10
如何使用PowerShell重启路由器?
\n我的电脑使用网线连接到路由器,路由器充当调制解调器,它通过 PPPoE 连接到 ISP,我的电脑位于 NAT 之后。
\n我的路由器型号:华为HS8545M,局域网地址:192.168.1.1,网页管理员登录名:CMCCAdmin,网页管理员密码:aDm8H%MdA。
\n我必须执行以下操作才能重新启动路由器(总共点击 7 次,浏览器会记住登录名和密码):
\n\n\n步骤太多了。
\n我尝试过使用这种方法:
\n$ie = New-Object -ComObject \'internetExplorer.Application\'\n$ie.Navigate "https://192.168.1.1"\n
Run Code Online (Sandbox Code Playgroud)\n但过了一会儿就失去了联系.Document
为空,尝试刷新会导致此错误:
OperationStopped: The RPC server is unavailable. (0x800706BA)\n
Run Code Online (Sandbox Code Playgroud)\n我使用的是 Windows 10 20H2,我禁用了远程桌面、远程协助、远程注册表、Windows 远程管理和许多其他功能,我禁用了远程功能,因为它们对安全构成威胁,我认为它们与此相关;顺便一提,RPC
服务正在运行。
谁能帮我?
\n第一页源代码: page1.html
\n第二页源代码: page2.html
\n这应该很简单,登录192.168.1.1,创建一个cookie,然后使用cookie进入192.168.1.1/index.asp,提交Restart_button,工作完成,但是我不太熟悉处理网络的命令...
\n我目前正在寻找Python的方式,我使用的是Python 3.9.1 amd64,我很早就把它放在PATH中,我已经通过pip安装了Selenium和Twill。下载GeckoDriver.exe并将其解压到Python安装文件夹中;
\n我知道 selenium、twill、urllib、urllib2、cookielib 和 webbot,都能够做到这一点,我目前正在尝试找出如何以最好的方式做到这一点。
\n我已经成功通过 twill 在 Python 中登录路由器,但是我不知道下一步该做什么:
\nfrom twill.commands import *\ngo(\'http://192.168.1.1\')\nshowforms()\nfv("1","txt_Username","CMCCAdmin")\nfv("1","txt_Password","aDm8H%MdA")\nshowforms()\nsubmit(\'btnSubmit\')\ngo("http://192.168.1.1/index.asp")\n
Run Code Online (Sandbox Code Playgroud)\n\n按钮:
\n<input type="button" name="Restart_button" id="Restart_button" class="submit" style="width:98px" onclick="Reboot()" value="\xe9\x87\x8d\xe5\x90\xaf">\n
Run Code Online (Sandbox Code Playgroud)\n它位于:
\nhtml.body.#container.#center.#content.table.tbody.tr.td.#frameContent.html.body.div.#Restart_button\n
Run Code Online (Sandbox Code Playgroud)\n另外,inputfields
第一页的(http://192.168.1.1):
PS C:\\Windows\\System32> $html.inputfields\n\nouterHTML : <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"/>\ntagName : INPUT\nname : txt_Username\ntype : text\nid : txt_Username\nstyle : float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;\nmaxlength : 31\n\nouterHTML : <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;"\n maxlength="31"/>\ntagName : INPUT\nname : txt_Password\ntype : password\nid : txt_Password\nmaxlength : 31\nstyle : float:left;padding:0;width:218px;height:38px;line-height:38px;text-indent:0.5em;border:0 solid green;background-color:transparent;\n\nouterHTML : <input type="button" id="btnSubmit" name="btnSubmit" value="\xe7\xa1\xae\xe5\xae\x9a" onclick="SubmitForm();" class="button_css"/>\ntagName : INPUT\ntype : button\nid : btnSubmit\nname : btnSubmit\nvalue : \xe7\xa1\xae\xe5\xae\x9a\nonclick : SubmitForm();\nclass : button_css\n\nouterHTML : <input type="reset" name="Submit2" value="\xe5\x8f\x96\xe6\xb6\x88" onclick="canceltext();" class="button_css"/>\ntagName : INPUT\ntype : reset\nname : Submit2\nvalue : \xe5\x8f\x96\xe6\xb6\x88\nonclick : canceltext();\nclass : button_css\n
Run Code Online (Sandbox Code Playgroud)\n我已经得到了重置页面的源代码:
\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<meta http-equiv="Pragma" content="no-cache" />\n<link rel="stylesheet" href=\'../../../../Cuscss/frame.css?2020070716413845-1425773353\' type=\'text/css\'>\n<script language="JavaScript" src="../../../resource/common/util.js?2020070716413845-1425773353"></script>\n<script language="JavaScript" type="text/javascript">\n\nfunction LoadFrame()\n{\n}\n\n\nfunction Reboot()\n{\nif(ConfirmEx("\xe7\xa1\xae\xe5\xae\x9a\xe8\xa6\x81\xe9\x87\x8d\xe5\x90\xaf\xe8\xae\xbe\xe5\xa4\x87\xe5\x90\x97?"))\n{\nsetDisable(\'Restart_button\', 1);\nsetDisable(\'Restore_button\', 1);\nsetDisable(\'btnRestoreDftCfg\', 1);\nvar Form = new webSubmitForm();\n\nForm.setAction(\'set.cgi?x=\' + \'InternetGatewayDevice.X_HW_DEBUG.SMP.DM.ResetBoard\'\n + \'&RequestFile=html/ssmp/devmanage/cmccdevicereset.asp\');\nForm.addParameter(\'x.X_HW_Token\', getValue(\'onttoken\'));\nForm.submit();\n}\n}\n\n</script>\n</head>\n<body class="mainbody" onLoad="LoadFrame();">\n\n<div class="func_spread"></div>\n<div class="title_with_desc">\n<label id="Title_reboot_lable">\xe8\xae\xbe\xe5\xa4\x87\xe9\x87\x8d\xe5\x90\xaf</label>\n</div>\n<div class="title_01" style="padding-left:10px;" width="100%">\n<label id="Title_reboot_tips_lable">\xe7\x82\xb9\xe5\x87\xbb\xe5\xa6\x82\xe4\xb8\x8b\xe6\x8c\x89\xe9\x92\xae\xe9\x87\x8d\xe5\x90\xaf\xe8\xb7\xaf\xe7\x94\xb1\xe5\x99\xa8\xe3\x80\x82</label>\n</div>\n<div class="button_spread"></div>\n<div align="right">\n<input type="hidden" name="onttoken" id="hwonttoken" value="de0f5f98c4d4a77239ccb981cd5c4bf3">\n<input type=\'button\' name="Restart_button" id="Restart_button" class="submit" style="width:98px" onClick=\'Reboot()\' value="\xe9\x87\x8d\xe5\x90\xaf">\n</div>\n</body>\n</html>\n
Run Code Online (Sandbox Code Playgroud)\n它位于地址:
\nhttp://192.168.1.1/html/ssmp/devmanage/cmccdevicereset.asp\n
Run Code Online (Sandbox Code Playgroud)\n另外我真的不知道Submit(\'btnSubmit\')
我是否登录,我不完全确定......
尽管这可行,但 Firefox 的初始化速度非常慢。
\n我终于弄清楚如何通过 telnet 方式做到这一点:
\ntelnet 192.168.1.1\nroot\nadminHW\nreset\n
Run Code Online (Sandbox Code Playgroud)\n如何使其成为自动输入命令的脚本?
\n我已经做到了……再一次!
PowerShell + VBScript + Telnet 的方式来做到这一点:
set router = CreateObject ("WScript.Shell")
router.run("Telnet")
WScript.Sleep 750
router.sendkeys("Open 192.168.1.1")
router.sendkeys("{Enter}")
WScript.Sleep 750
router.sendkeys("root")
router.sendkeys("{Enter}")
WScript.Sleep 750
router.sendkeys("adminHW")
router.sendkeys("{Enter}")
WScript.Sleep 750
router.sendkeys("reset")
router.sendkeys("{Enter}")
Run Code Online (Sandbox Code Playgroud)
另存为RebootModem.vbs
Start-Process -Filepath cscript.exe -Argumentlist $PSScriptRoot\RebootModem.vbs
Start-Sleep -Seconds 6
Get-Process -Name Telnet | Stop-Process
Run Code Online (Sandbox Code Playgroud)
另存为RebootModem.ps1
运行RebootModem.ps1
通过Telnet重新启动调制解调器,并在6秒后自动关闭Telnet.exe。
纯PowerShell方法:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
Start-Process -Filepath Telnet.exe -Argumentlist 192.168.1.1
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("root")
[System.Windows.Forms.SendKeys]::SendWait("{Enter}")
[System.Windows.Forms.SendKeys]::SendWait("adminHW")
[System.Windows.Forms.SendKeys]::SendWait("{Enter}")
[System.Windows.Forms.SendKeys]::SendWait("reset")
[System.Windows.Forms.SendKeys]::SendWait("{Enter}")
Get-Process -Name Telnet | Stop-Process
Run Code Online (Sandbox Code Playgroud)
它可以在 3 秒内完成工作。我确定这确实是最有效的方法。
归档时间: |
|
查看次数: |
3315 次 |
最近记录: |