The officially official Devuan Forum!

You are not logged in.

#1 2018-08-09 17:29:58

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

Last edited by GNUser (2018-08-12 19:21:53)

Offline

#2 2018-08-09 21:53:34

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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

Did you forget to ask your favourite search engine smile

Mine came up with https://community.netgear.com/t5/Wired- … d-p/495136 which suggests a simple curl command... though I can't test and confirm.

Offline

#3 2018-08-10 14:31:31

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

I had done some searches, but didn't uncover anything promising. I'll try my luck with what you found. Thank you.

Offline

#4 2018-08-11 02:00:04

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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:

bruno@eeepc:~$ ping 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
64 bytes from 192.168.100.1: icmp_seq=1 ttl=64 time=0.554 ms
64 bytes from 192.168.100.1: icmp_seq=2 ttl=64 time=0.509 ms
64 bytes from 192.168.100.1: icmp_seq=3 ttl=64 time=0.511 ms
^C
--- 192.168.100.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.509/0.524/0.554/0.033 ms

bruno@eeepc:~$ traceroute 192.168.100.1
traceroute to 192.168.100.1 (192.168.100.1), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 6  *^C

bruno@eeepc:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         c-73-226-66-1.h 0.0.0.0         UG    0      0        0 eth0
73.226.66.0     *               255.255.254.0   U     0      0        0 eth0
192.168.10.0    *               255.255.255.0   U     0      0        0 wlan0

Here are same commands run in router, with openvpn ON and router CANNOT connect to modem:

bruno@eeepc:~$ ping 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
^C
--- 192.168.100.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms

bruno@eeepc:~$ traceroute 192.168.100.1
traceroute to 192.168.100.1 (192.168.100.1), 30 hops max, 60 byte packets
 1  10.60.10.1 (10.60.10.1)  15.734 ms  23.761 ms  24.069 ms
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  *^C

bruno@eeepc:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.60.10.5      128.0.0.0       UG    0      0        0 tun0
default         c-73-226-66-1.h 0.0.0.0         UG    0      0        0 eth0
10.60.10.1      10.60.10.5      255.255.255.255 UGH   0      0        0 tun0
10.60.10.5      *               255.255.255.255 UH    0      0        0 tun0
73.226.66.0     *               255.255.254.0   U     0      0        0 eth0
107.191.33.9.ch c-73-226-66-1.h 255.255.255.255 UGH   0      0        0 eth0
128.0.0.0       10.60.10.5      128.0.0.0       UG    0      0        0 tun0
192.168.10.0    *               255.255.255.0   U     0      0        0 wlan0

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.

Last edited by GNUser (2018-08-11 02:20:44)

Offline

#5 2018-08-11 03:51:36

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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

It might be enough to add a host route through eth0:

route add 192.168.100.1 dev eth0

Offline

#6 2018-08-11 12:11:18

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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.

Last edited by GNUser (2018-08-11 12:13:06)

Offline

#7 2018-08-11 12:18:48

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

Here is what I see when I point browser to http://192.168.100.1, after entering username and password:
1.jpg

After clicking on "Advanced" I see this:
2.jpg

Then clicking on "Reboot" reboots the router.

Any idea how I would script visiting http://192.168.100.1 (with username and password), then clicking on "Advanced", waiting a moment, then clicking on "Reboot"?

Last edited by GNUser (2018-08-11 12:20:56)

Offline

#8 2018-08-11 12:52:48

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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.

Offline

#9 2018-08-11 13:27:13

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

I'm using Firefox 59, which does have an inspect tool. Result of inspecting the Reboot button:

reboot.png

I don't see a url associated with the reboot button, but onclick="advButtonClick(2)" looks promising. Any ideas where to go from there?

Also, wget and curl cannot authenticate, even though username and password are correct (yes, the default password is "password"):

bruno@thinkpad:~$ wget --user admin --password password http://192.168.100.1/goform/RouterStatus
--2018-08-11 14:58:01--  http://192.168.100.1/goform/RouterStatus
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 

bruno@thinkpad:~$ curl --user admin:password http://192.168.100.1/goform/RouterStatus<HTML>
<HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
</HTML><HR>
Error: 401 Unauthorized</TITLE></HEAD>

Last edited by GNUser (2018-08-11 19:45:09)

Offline

#10 2018-08-11 18:48:51

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

I saved all the html code of the modem's web interface (from Firefox's File -> Save page as -> Web page, complete), and found this in the RouterStatus.html file (note the code under index==2):

function advButtonClick(index){

    if(index==0) // Show Statistics
        openStatisticsWindow();
    else if(index==1)
    {    
        openStatusWindow();
		// document.forms[0].buttonSelect.value="1";
    }
    else if(index==2)
    {
        if(confirm("Rebooting the gateway will disrupt active traffic on the network. Are you sure?"))
        {
            document.forms[0].buttonSelect.value="2";
            document.forms[0].submit(document.forms[0]);
        }
    }
	else if (index==3)
	{
		if(confirm("Loading the factory default settings will erase all the current settings. Are you sure?"))
        {
            document.forms[0].buttonSelect.value="3";
            document.forms[0].submit(document.forms[0]);
        }
	}
}

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

Last edited by GNUser (2018-08-11 19:07:36)

Offline

#11 2018-08-11 19:10:59

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

I also tried curl with --anyauth, still no luck:

bruno@thinkpad:~$ curl --verbose --anyauth --user "admin:password" http://192.168.100.1/goform/RouterStatus
*   Trying 192.168.100.1...
* TCP_NODELAY set
* Connected to 192.168.100.1 (192.168.100.1) port 80 (#0)
> GET /goform/RouterStatus HTTP/1.1
> Host: 192.168.100.1
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: Basic realm="NETGEAR CM400"
< Server: NET-DK/1.0
< Date: Sat, 11 Aug 2018 14:41:54 GMT
< Set-Cookie: XSRF_TOKEN=3290479476; Path=/
< Content-Type: text/html
< Connection: close
< Pragma: no-cache
< 
* Curl_http_done: called premature == 0
* Closing connection 0
* Issue another request to this URL: 'http://192.168.100.1/goform/RouterStatus'
* Hostname 192.168.100.1 was found in DNS cache
*   Trying 192.168.100.1...
* TCP_NODELAY set
* Connected to 192.168.100.1 (192.168.100.1) port 80 (#1)
* Server auth using Basic with user 'admin'
> GET /goform/RouterStatus HTTP/1.1
> Host: 192.168.100.1
> Authorization: Basic YWRtaW46RXVjbGlka2s=
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 401 Unauthorized
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="NETGEAR CM400"
< Server: NET-DK/1.0
< Date: Sat, 11 Aug 2018 14:41:54 GMT
< Set-Cookie: XSRF_TOKEN=3290479476; Path=/
< Content-Type: text/html
< Connection: close
< Pragma: no-cache
< 
<HTML>
<HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
</HTML><HR>
Error: 401 Unauthorized</TITLE></HEAD>
* Curl_http_done: called premature == 0
* Closing connection 1

Last edited by GNUser (2018-08-11 19:44:05)

Offline

#12 2018-08-11 22:44:15

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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.

Offline

#13 2018-08-11 22:57:38

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

Offline

#14 2018-08-11 23:02:15

golinux
Administrator
Registered: 2016-11-25
Posts: 1,224  

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

GNUser wrote:

Wow, ralph.ronnquist, you know your stuff.

He is a digital ninja.

Offline

#15 2018-08-12 11:34:58

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

I was unable to make any progress with curl, but was able to make progress using python and its selenium module:

#!/usr/bin/python

import time
from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://admin:password@192.168.100.1/')
time.sleep(5)
alert = browser.switch_to_alert()
alert.accept()
time.sleep(5)
advancedTab = browser.find_element_by_xpath('/html/body/table/tbody/tr/td[2]/table[2]/tbody/tr/td/ul/li[2]/a/span')
advancedTab.click()
time.sleep(5)
rebootButon = browser.find_element_by_xpath('/html/body/form[1]/div/div/div/table/tbody/tr[1]/td/div/div[1]/table/tbody/tr/td/table/tbody/tr[10]/td/button[2]')
rebootButton.click()

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.

Last edited by GNUser (2018-08-12 11:56:37)

Offline

#16 2018-08-12 12:34:44

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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

Offline

#17 2018-08-12 19:20:16

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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:

#!/usr/bin/python

from selenium import webdriver
import time
import os

browser = webdriver.Firefox()
browser.get('http://admin:password@192.168.100.1/')
time.sleep(5)
alert = browser.switch_to_alert()
alert.accept()
time.sleep(5)
advancedTab = browser.find_element_by_link_text('ADVANCED')
advancedTab.click()
time.sleep(5)
os.system('xdotool mousemove --sync 650 420; xdotool click --repeat 1 --delay 125 1')
time.sleep(5)
alert = browser.switch_to_alert()
alert.accept() 

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.

Last edited by GNUser (2018-08-12 19:20:42)

Offline

#18 2018-08-12 20:23:46

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

@ralph.ronnquist: Things are looking good for wget.

First, I noticed that typing "http://192.168.100/RouterStatus.htm" in my webbrowser takes me directly to the page on the modem with the Reboot button.

Then, I tried this wget command and noticed that after initial "401 Unauthorized" error, authentication succeeds:

bruno@thinkpad:~$ wget -v --http-user admin --http-password password "http://192.168.100.1/RouterStatus.htm"
--2018-08-12 16:19:17--  http://192.168.100.1/RouterStatus.htm
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 50638 (49K) [text/html]
Saving to: ‘RouterStatus.htm’

RouterStatus.htm    100%[===================>]  49.45K  --.-KB/s    in 0.03s   

2018-08-12 16:19:17 (1.68 MB/s) - ‘RouterStatus.htm’ saved [50638/50638]

If you'd like to see what "RouterStatus.htm" looks like, it is here.

The missing piece is to add something to the command that sends the appropriate button press. Any ideas?

Last edited by GNUser (2018-08-12 20:26:14)

Offline

#19 2018-08-12 23:18:36

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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

From a glance into the html page, it should work nicely with a single request like the following:

wget --http-user admin --http-password password --post-data 'button=2' http://192.168.100.1/goform/RouterStatus?id=1232362831

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:

wget --http-user admin --http-password password --post-data 'button=2' \
    http://192.168.100.1$(wget -v --http-user admin --http-password password \
       http://192.168.100.1/RouterStatus.htm | sed '/action/ s/.*n="\([^"]*\).*/\1/')

On the other hand, since your method works, you might as well keep that.

Offline

#20 2018-08-13 00:19:57

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

First command:

bruno@thinkpad:~$ wget --http-user admin --http-password password --post-data 'button=2' http://192.168.100.1/goform/RouterStatus?id=1232362831
--2018-08-12 19:58:22--  http://192.168.100.1/goform/RouterStatus?id=1232362831
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3558 (3.5K) [text/html]
Saving to: ‘RouterStatus?id=1232362831’

RouterStatus?id=123 100%[===================>]   3.47K  --.-KB/s    in 0s      

2018-08-12 19:58:22 (16.8 MB/s) - ‘RouterStatus?id=1232362831’ saved [3558/3558]

Fetched this.

Second command:

bruno@thinkpad:~$ wget --http-user admin --http-password password --post-data 'button=2' http://192.168.100.1/goform/RouterStatus?id=$(( $(date +%s) - 301751682))
--2018-08-12 19:59:08--  http://192.168.100.1/goform/RouterStatus?id=1232366666
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3558 (3.5K) [text/html]
Saving to: ‘RouterStatus?id=1232366666’

RouterStatus?id=123 100%[===================>]   3.47K  --.-KB/s    in 0s      

2018-08-12 19:59:08 (91.2 MB/s) - ‘RouterStatus?id=1232366666’ saved [3558/3558]

Fetched this.

Third command:

bruno@thinkpad:~$ wget --http-user admin --http-password password --post-data 'button=2' http://192.168.100.1$(wget -v --http-user admin --http-password password http://192.168.100.1/RouterStatus.htm | sed '/action/ s/.*n="\([^"]*\).*/\1/')
--2018-08-12 20:08:19--  http://192.168.100.1/RouterStatus.htm
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 50638 (49K) [text/html]
Saving to: ‘RouterStatus.htm’

RouterStatus.htm    100%[===================>]  49.45K  --.-KB/s    in 0.03s   

2018-08-12 20:08:19 (1.52 MB/s) - ‘RouterStatus.htm’ saved [50638/50638]

--2018-08-12 20:08:19--  http://192.168.100.1/
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="NETGEAR CM400"
Connecting to 192.168.100.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52037 (51K) [text/html]
Saving to: ‘index.html’

index.html          100%[===================>]  50.82K  --.-KB/s    in 0.02s   

2018-08-12 20:08:19 (2.10 MB/s) - ‘index.html’ saved [52037/52037]

Fetched this and this.

Last edited by GNUser (2018-08-13 00:31:54)

Offline

#21 2018-08-13 00:35:35

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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?

Last edited by GNUser (2018-08-13 01:10:41)

Offline

#22 2018-08-13 03:26:37

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 253  

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.

Offline

#23 2018-08-13 11:50:01

GNUser
Member
Registered: 2017-03-16
Posts: 397  

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

ralph.ronnquist, all your input gave rise to this command, which MAKES THE MODEM REBOOT smile

bruno@thinkpad:~$ id=$(wget -O- --http-user admin --http-password password http://192.168.100.1/RouterStatus.htm | perl -lne '/id=([0-9]+)/ && print $1'); wget --http-user admin --http-password password --post-data 'buttonSelect=2' http://192.168.100.1/goform/RouterStatus?id="$id"

This is exactly the kind of elegant solution I was hoping to find.

Incidentally, the id is important. If I use a random number (with the correct number of digits) or an id that showed up before, it doesn't work.

I had no idea it would turn out to be this complicated, and not in a million years could I have figured this out without your tireless help and amazing skills. Thank you so much!

(BTW, both my modem and router are in hard-to-reach places. When I've had to reboot them, it's always been a huge hassle. Now I can just push a button on my phone and it all happens automatically!)

Last edited by GNUser (2018-08-13 12:32:16)

Offline

Board footer