Community discussions

MikroTik App
 
laxduke
just joined
Topic Author
Posts: 11
Joined: Sun Oct 03, 2004 6:36 pm

Help needed for making a script for DOCSIS modem reset

Thu Apr 02, 2020 7:46 pm

Hello.
I am trying to make a script which can reboot a DOCSIS 3.0 modem if it 'hangs' during operation.
Mikrotik router will check it from lan side since WAN would be down probably.
First thing that i did is to use the following command to login to modem and download login page to Mikrotik flash nand.

/tool fetch url="http://192.168.100.1/login.asp" user=admin password=admin dst-path=/logininfo.txt

Just to mention that file downloaded is larger then 4096 bytes.

At the same time i did a dump with wireshark and looked into the file to find the required string.
This is the dump from the windows pc machine :

HTML Form URL Encoded: application/x-www-form-urlencoded
Form item: "CSRFValue" = "79822754"
Key: CSRFValue
Value: 79822754
Form item: "loginUsername" = "admin"
Key: loginUsername
Value: admin
Form item: "loginPassword" = "admin"
Key: loginPassword
Value: admin
Form item: "logoffUser" = "0"
Key: logoffUser
Value: 0




The important field for script to to use token value of "79822754" with next login where i want to use POST command to send reboot instruction
to modem.
Problem is that i do not know how to extract value for key CSRFValue.
I would then use it as a :local value.
When i try next line i must have CSRFValue negotiated with modem in order for it to accept POST to it.
/tool fetch mode=http user="admin" password="admin" http-method=post http-header-field="content-type:application/x-www-form-urlencoded" http-data="mCmReset = 1 " url="http://192.168.100.1/goform/RgSecurity"
I am also uncertain if http-data string is correct.
http://192.168.100.1/goform/RgSecurity is page on which option for rebooting resides

Here is the dump from wireshark :
HTML Form URL Encoded: application/x-www-form-urlencoded
Form item: "CSRFValue" = "79822754"
Key: CSRFValue
Value: 79822754
Form item: "HttpUserId" = "admin"
Key: HttpUserId
Value: admin
Form item: "Password" = ""
Key: Password
Value:
Form item: "PasswordReEnter" = ""
Key: PasswordReEnter
Value:
Form item: "RestoreConfirmPop" = "0"
Key: RestoreConfirmPop
Value: 0
Form item: "RestoreFactoryNo" = "0x00"
Key: RestoreFactoryNo
Value: 0x00
Form item: "mCmReset" = "1"
Key: mCmReset
Value: 1

When modem receives "mCmReset" = "1" value it reboots itself.
With curl from linux/unix everything works but i am having trouble to do it with Mikrotik alone.
I hope that scripting experts can come to help, i think this script could be beneficial to many people once it's functional.

Thank you in advance

Who is online

Users browsing this forum: caldo85 and 34 guests