Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) SSH Commands to Sophos Router Device ConsoleDemonstrates how to establish an SSH session with a Sophos XG router and send commands in a device console session.
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oSsh = ObjCreate("Chilkat.Ssh") Local $bSuccess = $oSsh.Connect("172.16.16.16",22) If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; Authenticate using login/password: $bSuccess = $oSsh.AuthenticatePw("myLogin","myPassword") If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; Start a shell session. ; (The QuickShell method was added in Chilkat v9.5.0.65) Local $iChannelNum = $oSsh.QuickShell() If ($iChannelNum < 0) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; The Sophos router will send this initial prompt: ; Main Menu ; ; 1. Network Configuration ; 2. System Configuration ; 3. Route Configuration ; 4. Device Console ; 5. Device Management ; 6. VPN Management ; 7. Shutdown/Reboot Device ; 0. Exit ; ; Select Menu Number [0-7]: $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"Select Menu Number","utf-8",True) If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; Show what we received so far: ConsoleWrite($oSsh.GetReceivedText($iChannelNum,"utf-8") & @CRLF) ; Send "4" <RETURN> to mimic typing in a shell session. $bSuccess = $oSsh.ChannelSendString($iChannelNum,"4" & @LF,"utf-8") If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; We should get a "console>" prompt. $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"console>","utf-8",True) If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ConsoleWrite($oSsh.GetReceivedText($iChannelNum,"utf-8") & @CRLF) ; Send a command and get the output.. $bSuccess = $oSsh.ChannelSendString($iChannelNum,"dnslookup host google.com" & @LF,"utf-8") $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"console>","utf-8",True) If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ConsoleWrite($oSsh.GetReceivedText($iChannelNum,"utf-8") & @CRLF) ; Send another command and get the output, and so on... $bSuccess = $oSsh.ChannelSendString($iChannelNum,"dnslookup host microsoft.com" & @LF,"utf-8") $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"console>","utf-8",True) If ($bSuccess <> True) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ConsoleWrite($oSsh.GetReceivedText($iChannelNum,"utf-8") & @CRLF) $oSsh.Disconnect |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.