[SOLVED] how to reboot modem from router command line?

I have a GNU/Linux netbook which functions as my home router. The netbook is connected to a Netgear CM400 cable modem. The netbook is highly customized but the modem has not been modified in any way whatsoever.

Rebooting the netbook/router remotely is trivial, but for the life of me I can't figure out how to reboot the modem. Does anybody know how to reboot a modem remotely or from a shell running in one's router?

It is unacceptable that my ISP provider knows how to reboot my modem remotely, but I do not. I'd really like to know how to do this.

Re: [SOLVED] how to reboot modem from router command line?

Re: [SOLVED] how to reboot modem from router command line?

I am able to reboot modem from router, using modem's web interface. I'll figure out the curl syntax when I solve this problem:

Router runs openvpn so that all devices in my LAN are on VPN automatically. Problem is that router can only connect to modem at 192.168.100.1 when openvpn isn't running. When openvpn is running, router can't reach the modem.

Here is the output of some commands I ran in the router when openvpn is OFF and router CAN connect to modem:

It seems when openvpn is on, router tries reaching modem via tun0 interface. I think what I need is to tell the router to never use tun0 when trying to reach the modem. Unfortunately my network skills are mediocre so it's unlikely I can figure this out on my own.

Re: [SOLVED] how to reboot modem from router command line?

Thank you, ralph.ronnquist. That didn't work but when I added a gateway to your suggestion, it works:

route add 192.168.100.1 gw 73.226.66.1 dev eth0

Now the router can reach the modem regardless of whether openvpn is running or not.

So back to the original question. Right now I can only reboot the modem using the web interface. The curl command doesn't work, and my guess is that it's because the url the person in the Netgear forum was using (http://192.168.100.1/goform/RouterStatus) doesn't actually exist: Regardless of what buttons I press on the web interface, the address shown in the browser's address bar remains simply 192.168.100.1. I'll post some screenshots in a bit.

I think a CLI solution to rebooting the router would require scripting a visit to http://192.168.100.1, clicking on a button, waiting a moment, then clicking on another button.

Re: [SOLVED] how to reboot modem from router command line?

Most likely the router uses "basic authentication", which means that the username and password is passed on as an HTTP header with every request, and if so, you'll be able to pass it to curl (or wget) as part of its arguments. You'd use the inspect tool of the browser (hoping it has that) to find out the triggering url for the reboot button, and it'll work nicely with a single curl (or wget) command. The reboot url would be either a simple "get request", or possibly a "post request" action of a "form" in the page.

If your browser doesn't have an inspect tool, you should be able to save the page and view it in a plain text editor instead (looking for the "reboot" text).

If the authentication is something else, you might need the more complicated solution of running a "web monkey" (e.g. casperjs, or take your pick) to mimic the human gestures across the interface, relative to the browser document representations. It would however be a bit surprising to me if it offered that kind of complexity.

If anyone knows how to trigger the reboot function (including authenticating and answering in the affirmative the "are you sure?" question) from the command line, I would buy you a case of beer I'm totally stuck at this point, as I know relatively little about web design and, besides, I don't understand why curl fails to authenticate given that the username and password are definitely correct.

Re: [SOLVED] how to reboot modem from router command line?

Firstly about the authentication: it appears the modem uses cookies for session tracking; you see the Set-Cookie response header. That's slightly unfortunate as it might even mean you need to chain it all as two requests. Or maybe not. With curl, you use argument -b to tell it that cookies are in use, and -c x to store cookies in file x (and reuse from there).

Secondly about the URL. You will need to look into the HTML for the first <form .. action=...> and make note of its action. If that is a relative path, it would be appended to /goform. Thereafter you need to add the query parameter ?bbb=3, although that bbb you will find as the name of the button in the form. Or try with ?buttonSelect=3 (although that looks too easy). Also, if the form method is "POST" you may need to make it all a POST request rather, and then the query parameter would be added into the "data" part.

Re: [SOLVED] how to reboot modem from router command line?

Wow, ralph.ronnquist, you know your stuff. Thank you so much for all you help so far.

There are a lot of tips in your post. Hopefully somewhere in this treasure trove I will find the answer. I'll try different things based on your guidance and will report back when I hit a snag or find a solution.

(Incidentally, I never thought the answer to my question would be so complicated. On the one hand it is stressful. On the other hand, it forces me to learn some new things.)

This script gets me to the second screenshot in post #7. It then gets stuck at the next to last line because while the Reboot button is clearly visible to me (I can hover over it, view its attributes, copy its xpath and, of course, manually click it if I want), selenium cannot find the Reboot button. I tried many of the browser's find_element_by_* methods, trying to match on all of the button's attributes I could think of. There must be something very strange about how the modem's web interface was put together. Any ideas, or should I ask in a python/selenium forum?

P.S. I did some searches on how to trigger an onclick function (advButtonClick(2) in this case) in selenium without actually clicking the button, and did not find anything.

Re: [SOLVED] how to reboot modem from router command line?

My read buffer for python is rather limited I'm afraid, but I noticed you're using form[1] and that the javascript in post #10 submits a form[0]. I know javascript starts indexing from 0, and if python does the same, it might mean that the submitted form is actually a hidden element prior to the visible form. Perhaps there is a "tag name" selector in selenium offering the array of forms, to let you mimic the index==3 action.

Other than that, I think I'm out of ideas (well, suggesting an excursion with wget, perhaps, which also is cookie capable).

Re: [SOLVED] how to reboot modem from router command line?

Thanks for the suggestion, ralph.ronnquist. I tried searching for the Reboot button using form[0] instead of form[1] in the xpath, but no luck.

I gave up finding the Reboot button the "proper" way. For the step where Reboot button is pressed, I decided to cheat and use xdotool to simply click at the button's coordinates on the screen. So this is the kludge of a script I came up with to reboot my modem from the command line:

I find my solution ugly to the point of being offensive, but it will tide me over until I find something better--an excursion into wget is definitely in order. If I discover something elegant, I'll make sure to post it here.

However, that extra parameter id=1232362831 was generated for the page you saved, and it's not obvious how to make it up if it's different each time. It could possibly be a timestamp, if your modem's clock is off by 9 years or so. It might also be without special significance.

If it is a time stamp for an off clock, you'd generate a new one with something like $(( $(date +%s) - 301751682))

If it is significant, you will need to first get the page (as you did), and then pick the form action from it (e.g. with sed). You would then put these two wget together into a single command line like the following (where back-slash is immediately followed by new-line), perhaps:

Re: [SOLVED] how to reboot modem from router command line?

I really didn't like my solution and as long as this remains interesting to you, I'm committed to finding a cleaner solution.

Yes, I had noticed the unexplained id=1232362831 parameter. It seems to be different each time, but it is not obvious what it is. I just ran the same command I ran in post #18 and this time it was id=1823045111, so it does not appear to be a timestamp.

I tried all three commands you suggested. While no errors were reported, none of the commands caused the modem to reboot. Here are the three commands and their terminal output, as well as the fetched file(s):

Re: [SOLVED] how to reboot modem from router command line?

Just a thought: When I manually click on the Reboot button, I get a popup ("Rebooting the gateway will disrupt active traffic on the network. Are you sure?" Cancel/OK). Could it be that one or more of our wget commands is successfully pressing the Reboot button but not answering "OK" to the popup? Maybe this is a stupid question because wget requests don't trigger confirmation popups since no javascript is involved?

Re: [SOLVED] how to reboot modem from router command line?

The "confirm" popup is in the RouterStatus.htm script to come up before the reboot request gets issued; so it's before that wget request gets issued.

When checking the file again with more care, I realized that there is the hidden input field named buttonSelect. Thus that should be the name used in the post data. I.e., try using buttonSelect=2 instead of button=2.

Since both 1.htm and 2.htm are the same progress bar response, it suggests that the id number is not very important. Thus option 1 may well work with buttonSelect=2.

The complex, third, variant doesn't work at all as is, which is my fault. It should have -O- instead of -v; you will want the download of the inner wget to go to standard output, and piped to sed, which extracts the form action (with path and id) to be used by the outer wget.

Though the complex variant is only needed if the id number is important. If there also is a connection to the session cookie, the command might need to be made even more complex, so as to making the inner wget save the cookie, and the outer load it.