youtuber Posted March 4, 2018 Share Posted March 4, 2018 I can manually restart via cmd. Spoiler But how can I do this with a single click with autoit tcp commands? I made an attempt but failed TCPStartup() $Connect = TCPConnect("192.168.1.1", 23) TCPSend($Connect, "root") TCPSend($Connect, "password") TCPSend($Connect, "reboot") TCPCloseSocket($Connect) TCPShutdown() Link to comment Share on other sites More sharing options...
Developers Jos Posted March 4, 2018 Developers Share Posted March 4, 2018 (edited) 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 March 4, 2018 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 More sharing options...
ripdad Posted March 4, 2018 Share Posted March 4, 2018 Also, each command you send must end with @LF or @CRLF youtuber 1 "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 More sharing options...
youtuber Posted March 4, 2018 Author Share Posted March 4, 2018 I do not know if there is a mistake in my spelling I do not know about tcp expandcollapse popupGlobal $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 Link to comment Share on other sites More sharing options...
ripdad Posted March 4, 2018 Share Posted March 4, 2018 (edited) Should be close enough -- Not tested. Tested with my router... expandcollapse popupOpt('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 March 5, 2018 by ripdad Bilgus and youtuber 2 "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 More sharing options...
ripdad Posted March 5, 2018 Share Posted March 5, 2018 (edited) 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 March 5, 2018 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 More sharing options...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 Its a lot better than trying to automate a telenet session but do be aware leaving telenet open on your router is a bad idea from a security perspective Link to comment Share on other sites More sharing options...
ripdad Posted March 5, 2018 Share Posted March 5, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now