3/26/2023 0 Comments Purebasic cisco![]() ![]() The data in the response could contain the "#" char. We don't want to check for only "#" because it's not specific enough. Change "YOUR_PROMPT" to your actual prompt. Consume the response until we end with another prompt. Success = CkSsh:: ckChannelSendString(ssh,channelNum, "show running-config" + Chr(13), "utf-8") The response will be in multiple pages, each ending with "-More-" and requiring a SPACE bar to be sent to get the next page. Success = CkSsh:: ckChannelReceiveUntilMatch(ssh,channelNum, "#", "utf-8", 1) The prompt now changes from "Something>" to "Something#> Read until the new prompt. Success = CkSsh:: ckChannelSendString(ssh,channelNum, "MY_PASSWORD_FOR_ELEVATED_PRIVILEGE" + Chr(13), "utf-8") ProcedureReturn EndIf Show what we received. Success = CkSsh:: ckChannelReceiveUntilMatch(ssh,channelNum, "Password:", "utf-8", 1) Assume success for this example to make it shorter. Success = CkSsh:: ckChannelSendString(ssh,channelNum, "ena" + Chr(13), "utf-8") (For the Cisco switch, terminate command with a single CR char.) Send the "ena" command to enable privileged mode. ![]() ProcedureReturn EndIf Show what we received so far:ĭebug CkSsh:: ckGetReceivedText(ssh,channelNum, "utf-8") Success = CkSsh:: ckChannelReceiveUntilMatch(ssh,channelNum, ">", "utf-8", 1) (It's not actually required that we do this, but it helps to know that all is OK at this point.) If channelNum ", then read until we get the prompt. ProcedureReturn EndIf Start a shell session. Success = CkSsh:: ckAuthenticatePw(ssh, "myLogin", "myPassword") ProcedureReturn EndIf Authenticate using login/password: Success.i = CkSsh:: ckConnect(ssh, "SSH_SERVER_DOMAIN_OR_IP_ADDRESS", 22) ![]() See Global Unlock Sample for sample code. This example assumes the Chilkat API to have been previously unlocked. (PureBasic) SSH to Cisco Switch - Processing "More" Responsesĭemonstrates connecting to a Cisco switch, running a command to enable privileged mode, then running a command to get a paged response requiring the SPACE char to be sent to process "-More-". ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |