Maurizio
Maurizio

Reputation: 189

Rebooting a Netgear XWn5001

I have a Netgear power extender that I'd need to reboot programmatically and remotely.

I was wondering if anybody here is able to understand from this code how it could be done. This is the page on the GUI just before pressing the button (yes) to reboot it.

    <!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. for a Netgear router adding 'reboot' after the address reboots it (really ? :-) ), here it is not the case.

I'm looking for a way to have a single html address-like to be sent via ironpython or powershell to reboot it.

As I'm not into HTML, I am seeking help.

thanks,

Maurizio

* EDIT * I created some Ironpython code following the suggestions:

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 contains whta was explained before, "/apply.cgi?/reboot_waiting.htm timestamp=57845968" with the timestamp read from the page, so i suppose valid.

but nothing happens, no reboot... no errors...

Thanks for your help...

M

Upvotes: 0

Views: 631

Answers (2)

Maurizio
Maurizio

Reputation: 189

as usual, s soon as I edited it, I found the answer:

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()

using Fiddler and looking at the information I recreated the original page stream... it works now!!

Thanks to all for the help!

M

Upvotes: 0

Nasreddine
Nasreddine

Reputation: 37868

These are the interesting lines from the code you pasted:

<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>

When you click the "Yes" button a POST request is sent to this URL:

http://<address_of_your_netgear_equipement>/apply.cgi?/reboot_waiting.htm timestamp=31895276

with the following content in the request's body:

submit_flag=reboot&yes=Yes

The value of timestamp in the URL may vary (you'll have to figure out if it does by refreshing the form multiple times) and you might have to reproduce the login sequence to your device in order to obtain the session cookie.

Upvotes: 1

Related Questions