Community discussions

MikroTik App
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Script modem reboot

Mon Oct 05, 2020 3:18 pm

Is there a way to script a mikrotik so that if it looses network connection, it will call the modem website, log in, go to the reboot webpage and click the reboot button?

The case is that a mikrotik router is behind a modem. The network connection frequently goes down, and the only way to get back online is to reboot the modem. Usually the easy way is to manually unplug power for a few seconds, but there is also a web interface where there is a reboot button. So I was thinking I could schedule a script that runs every 5ish minutes - sends a ping to the isp, if no reply sends another ping to isp, if still no reply, reboot the modem. I've not been able to telnet or ssh to the modem. So the only way I've found to reboot is by using the webinterface. Is there any way to script that action?

If the mikrotik can't do it, maybe it's possible from a metarouter? From a pc it should be posible, just have to figure out how.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script modem reboot

Mon Oct 05, 2020 3:32 pm

Here is the solution for you:
power adapter.jpg
http://www.networktechinc.com/control-power.html#tab-5

Connect this power adapter on the power for the modem. Then set it to auto ping an IP address.
If ping stops, then the adapter power cycle the modem.
You do not have the required permissions to view the files attached to this post.
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Script modem reboot

Mon Oct 05, 2020 3:54 pm

I know about similar items. Problem is that the modem has battery that lasts for 6 hours.
When I said unplug power, that included pulling out the battery. It will not power on if battery is not installed.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script modem reboot

Mon Oct 05, 2020 8:19 pm

If you can not figure out what the problem hang is, then change modem, change ISP.
Rebooting should not be needed.
 
petterg
Member Candidate
Member Candidate
Topic Author
Posts: 230
Joined: Wed Sep 16, 2009 2:55 pm

Re: Script modem reboot

Tue Oct 06, 2020 1:30 am

There aren't any other isps in the area. They are using the 450MHz-band which is not supported by normal equipment.
 
User avatar
vecernik87
Forum Veteran
Forum Veteran
Posts: 882
Joined: Fri Nov 10, 2017 8:19 am

Re: Script modem reboot

Tue Oct 06, 2020 1:51 am

No matter what solution you choose, I agree that this is likely not doable with simple mikrotik script. Mikrotik can detect loss of connectivity and has simple, yet sufficient scripting language for any tasks done within RouterOS. It has no ability to interact with external tools except sending emails or fetching resources with HTTP GET/POST requests.

Now, this second part - HTTP requests - might be enough for your modem, but in reality it will likely fail because RouterOS does not support cookies (almost certainly required for login function on your modem). You may still try to investigate on your own, what kind of HTTP request has to go to the modem, in order to restart it (see "networks" tab in developers console in your web browser when you click the "reboot" button).

Personally, I would recommend to grab a raspberryPI or another cheap single-board-computer, install it next to the modem and use its full-blown linux OS to script this behavior.


edit: wow, I might be wrong assuming you can't use cookies... there are few forum posts which seemingly made it working so uh... if thats true, you might be able to "click" the reboot button virtually, by sending carefully crafted HTTP requests. This will still require some investigation from you, because you need to figure out correct HTTP request to log yourself in the modem, capture the cookie and finally send another HTTP request including the auth cookie to reboot the router.

Who is online

Users browsing this forum: No registered users and 14 guests