Jump to content

How to restart my modem with telnet


Recommended Posts

  • Developers

Which part do you think failed as you aren't doing any error checking and simply throwing data to the router at full speed?
Try adding some error checking to see whether each step is successfull before doing the next step... and maybe a pause here and there helps too.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I do not know if there is a mistake in my spelling I do not know about tcp

Global $err = @error
TCPStartup()
$Connect = TCPConnect("192.168.1.1", 23)
If $Connect = -1 Then
    ConsoleWrite($Connect & @crlf)
    Exit
EndIf

Sleep(500)
$recv = TCPRecv($Connect, 500)

If $recv <> "" then
ConsoleWrite('Received: ' & $recv & @crlf)
else
ConsoleWrite('got nothing? ' & $recv & ":: " & $err & @CRLF)
EndIf

TCPSend($Connect, "root" & @CRLF)

$recv2 = TCPRecv($Connect, 500)

If $recv2 <> "" then
ConsoleWrite('Received2: ' & $recv2 & @crlf)
else
ConsoleWrite('got nothing? ' & $recv2 & ":: " & $err & @CRLF)
EndIf

TCPSend($Connect, "password" & @CRLF)

$recv3 = TCPRecv($Connect, 500)

If $recv3 <> "" then
ConsoleWrite('Received3: ' & $recv3 & @crlf)
else
ConsoleWrite('got nothing? ' & $recv3 & ":: " & $err & @CRLF)
EndIf

TCPSend($Connect, "reboot" & @CRLF)

$recv4 = TCPRecv($Connect, 500)

If $recv4 <> "" then
ConsoleWrite('Received4: ' & $recv4 & @crlf)
else
ConsoleWrite('got nothing? ' & $recv4 & ":: " & $err & @CRLF)
EndIf

TCPCloseSocket($Connect)

TCPShutdown()

My console output

Spoiler

Screenshot_2.jpg

 

Link to comment
Share on other sites

Should be close enough -- Not tested.

Tested with my router...

Opt('MustDeclareVars', 1)
;
If Not TCPStartup() Then
    ConsoleWrite('Error: TCPStartup' & @CRLF)
    Exit
EndIf
;
Local $gui = GUICreate('', 400, 400)
Local $edt = GUICtrlCreateEdit('', 10, 10, 380, 380)
GUISetState(@SW_SHOW, $gui)
;
Local $nSocket = TCPConnect('192.168.1.1', 23); <- make sure ip and port are correct!
If @error Or $nSocket < 1 Then
    GUICtrlSetData($edt, 'Error: TCPConnect' & @CRLF, 1)
    Exit
Else
    GUICtrlSetData($edt, '-> Connected' & @CRLF, 1)
EndIf
;
Sleep(1000)
_Recv($nSocket)
;
Local $aCommand[4] = [3, 'root', 'password', 'reboot']; <- make sure commands are correct!
;
For $i = 1 To $aCommand[0]
    TCPSend($nSocket, $aCommand[$i] & @CRLF)
    If @error Then
        GUICtrlSetData($edt, 'Error: TCPSend' & @CRLF, 1)
        ExitLoop
    Else
        GUICtrlSetData($edt, '-> SEND: ' & $aCommand[$i] & @CRLF, 1)
        Sleep(1000)
        _Recv($nSocket)
        If @error Then
            ExitLoop
        EndIf
    EndIf
Next
;
GUICtrlSetData($edt, @CRLF & '-> EXIT' & @CRLF, 1)
Sleep(10000)
TCPCloseSocket($nSocket)
TCPShutdown()
Exit
;
Func _Recv($nSocket)
    Local $sRecv
    For $i = 1 To 25
        $sRecv = TCPRecv($nSocket, 2048, 1)
        If @error Then
            GUICtrlSetData($edt, 'Error: TCPRecv' & @CRLF, 1)
            Return SetError(1)
        ElseIf $sRecv <> '' Then
            GUICtrlSetData($edt, '-> RECEIVED: ' & BinaryToString($sRecv), 1)
            Return
        EndIf
        Sleep(10)
    Next
    GUICtrlSetData($edt, '-> No Response' & @CRLF, 1)
    Return
EndFunc
;

 

 

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

So, I got around to testing with my router and found a few things amiss.

(1) the commands are different.

Instead of: root, password, reboot

It needed: login, password, restart

(2) the received data was in binary.

Changed to binary mode on TCPRecv() and added BinaryToString() for incoming data.

The script above has been modified to reflect these changes.

 

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Yep, I personally would not leave it that way on a business network. A home network might be okay.

Still nice to be able to do it, depending on circumstances.

Personally, I just unplug it, wait 10 seconds and plug it back in.

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...