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 Cisco SwitchDemonstrates how to establish an SSH session with a Cisco switch (or something similar) 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.100",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. Local $iChannelNum = $oSsh.QuickShell() If ($iChannelNum < 0) Then ConsoleWrite($oSsh.LastErrorText & @CRLF) Exit EndIf ; If the CISCO switch returns a prompt with "#", then read until we get the prompt. ; (It's not actually required that we do this, but it helps to know that all is OK at this point..) $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"#","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 a "show clock" command. $bSuccess = $oSsh.ChannelSendString($iChannelNum,"show clock" & @LF,"utf-8") ; Read the output to the next interactive prompt. $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"#","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,"some other command" & @LF,"utf-8") $bSuccess = $oSsh.ChannelReceiveUntilMatch($iChannelNum,"#","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.