我有一台Netgear电源扩展器,我需要以编程方式和远程方式重新启动。
我想知道这里是否有人能够从这段代码中了解它是如何完成的。这是在按下按钮之前GUI上的页面(是)重新启动它。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><link rel="stylesheet" href="/style/form.css">
<script language=javascript type=text/javascript src=/funcs.js></script>
<script language=javascript type=text/javascript src=/backup.js></script>
<title>NETGEAR PLC AP XWN5001 </title><meta http-equiv=content-type content='text/html; charset=UTF-8'>
<meta content="MSHTML 6.00.2800.1141" name="GENERATOR"></head>
<body bgcolor=#ffffff>
<form method="POST" action="/apply.cgi?/reboot_waiting.htm timestamp=31895276">
<input type=hidden name=submit_flag value="reboot">
<div class="page_title">Reboot</div>
<div id="main" class="main">
<table width="100%" border="0" cellpadding="0" cellspacing="3">
<tr><td colSpan="2"><h1></h1></td></tr>
<tr>
<td nowrap colspan=2><B>Rebooting the device will disrupt active traffic on the network. Are you sure? </B></td>
</tr>
<TR><TD colspan=2><img src=/liteblue.gif width=100% height=12></TD></TR>
<tr>
<td nowrap colspan=2 align=center>
<input class="short_common_bt" type="submit" name="yes" value="Yes">
<input class="short_common_bt" type="button" name="no" value="No" onclick="location.href='RST_status.htm'">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
e.g。对于Netgear路由器在地址重新启动后添加'reboot'(真的?:-)),这不是这种情况。
我正在寻找一种方法来获得一个单独的html地址 - 比如通过ironpython或powershell发送它来重新启动它。
由于我没有使用HTML,我正在寻求帮助。
感谢,
莫里吉奥
*编辑* 我根据建议创建了一些Ironpython代码:
webReq = System.Net.HttpWebRequest.Create("http://192.168.1.155/" + cLink)
webReq.Method = "POST"
byData = System.Text.Encoding.ASCII.GetBytes("submit_flag=reboot&yes=Yes")
webReq.ContentLength = byData.Length
webWriter = webReq.GetRequestStream()
webWriter.Write(byData, 0, byData.Length)
webWriter.Flush()
webWriter.Close()
cLink包含之前解释过的“/apply.cgi?/reboot_waiting.htm timestamp = 57845968”,其中从页面读取时间戳,所以我认为是有效的。
但没有任何反应,没有重启......没有错误......
感谢您的帮助......
中号
答案 0 :(得分:1)
这些是您粘贴代码的有趣内容:
<form method="POST" action="/apply.cgi?/reboot_waiting.htm timestamp=31895276">
<input type=hidden name=submit_flag value="reboot">
<input class="short_common_bt" type="submit" name="yes" value="Yes">
<!-- the "No" button here is not used. It's just here to redirect you to another page in case you don't want to reboot -->
<input class="short_common_bt" type="button" name="no" value="No" onclick="location.href='RST_status.htm'">
</form>
当您点击“是”按钮时,会向此网址发送POST request:
http://<address_of_your_netgear_equipement>/apply.cgi?/reboot_waiting.htm timestamp=31895276
请求正文中包含以下内容:
submit_flag=reboot&yes=Yes
URL中timestamp
的值可能会有所不同(您必须通过多次刷新表单来确定它是否存在)并且您可能必须重新创建设备的登录序列才能获取会话cookie。
答案 1 :(得分:0)
webReq = System.Net.HttpWebRequest.Create("http://192.168.1.155/" + cLink)
webReq.Method = "POST"
webReq.CookieContainer = CookieContainer
webReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
webReq.Referer = ("http://192.168.1.155/reboot.htm")
webReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:31.0) Gecko/20100101 Firefox/31.0"
webReq.KeepAlive = True
webReq.AllowAutoRedirect = False
webReq.Credentials = NetworkCredential(cLogin, cPW)
webReq.Headers.Add("Authorization", auth)
webReq.Headers.Add("DNT: 1")
webReq.Headers.Add("Accept-Encoding: gzip, deflate")
webReq.ContentType = "application/x-www-form-urlencoded"
byData = System.Text.Encoding.ASCII.GetBytes("submit_flag=reboot&yes=Yes")
webReq.ContentLength = byData.Length
webWriter = webReq.GetRequestStream()
webWriter.Write(byData, 0, byData.Length)
webWriter.Flush()
webWriter.Close()
webWriter.Dispose()
使用Fiddler并查看我重新创建原始页面流的信息......现在可以使用!!
感谢大家的帮助!
中号