AutoIt
AutoIt
SSH Commands to Cisco Switch
See more SSH Examples
Demonstrates how to establish an SSH session with a Cisco switch (or something similar) and send commands in a device console session.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oSsh = ObjCreate("Chilkat.Ssh")
$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