vestanpance3110 Posted July 12, 2019 Share Posted July 12, 2019 Hi all, I have a GUI that allows the end user to select a network switch from a list that appears in a combobox . With the press of a button, they can then SSH to that switch using a combination of plink (putty for command line) and a CMD prompt. The following function works just fine. My only issue is that when it 'sends' keystrokes to the CMD prompt window, you see the following string which includes the users password in clear text, so it looks something like this.. C:\Users\vestanpance3110\Documents\AutoIT_Toolbar\Installed_Files\Apps>.\plink.exe -ssh vestanpance3110@myswitchname -pw Th!s15MyP@s5w0rd Func SSHSwitch() Local $switchname = GUICtrlRead($SwitchCombo) Local $Password = GUICtrlRead($TacacsPasswordInput) If GUICtrlRead($SwitchCombo) = "" Then Return Else Run(@ComSpec & ' /K ' & "cd /d " & @MyDocumentsDir & "\AutoIT_Toolbar\Installed_Files\Apps\") WinWait("[CLASS:ConsoleWindowClass]", "", 10) Send(".\plink.exe -ssh " & @UserName & "@" & $switchname & " -pw " & $Password) Sleep(50) Send("{ENTER}") Sleep(1000) Send("N" & "{ENTER}") Sleep(1000) Send("{ENTER}") Send("enable" & "{ENTER}") Sleep(500) Send($Password & "{ENTER}") Sleep(200) Send("{ENTER 4}") WinSetTitle("[CLASS:ConsoleWindowClass]", "", "Network Operations - plink.exe -ssh " & $switchname) EndIf EndFunc ;==>SSHSwitch I used the line Send("{ENTER 4}") simply to scroll the password out of view in the CMD prompt window. After playing around with $STDIN_CHILD + $STDOUT_CHILD (which i don't completely understand i admit) i managed to concoct this, which will SSH into the switch and issue a show version command (all text not visible) and the output from the switch will appear in the console, rather than the CMD window. Despite being able to send data to the CMD prompt, i can't actually use CMD prompt after the data has been sent via StdinWrite, as there it doesn't allow any interaction. (I do realise i'm killing the connection when i exit the switch, but if i don't the CMD box just remains open and unusable.) $CMD = Run(@ComSpec & ' /K ' & "cd /d " & @MyDocumentsDir & "\AutoIT_Toolbar\Installed_Files\Apps\","", @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD) sleep(500) StdinWrite($CMD, "plink.exe -ssh vestanpance3110@myswitchname -pw Th!s15MyP@s5w0rd" & @CRLF) sleep(1000) StdinWrite($CMD, "show version" & @CRLF) sleep(1000) StdinWrite($CMD, "exit" & @CRLF) sleep(1000) ;Calling StdinWrite without a second parameter closes the stream. StdinWrite($CMD) $Message = StdoutRead($CMD) Consolewrite($Message & @CRLF) Ideally i'd like to be able to send the login command (plink.exe -ssh vestanpance3110@myswitchname -pw Th!s15MyP@s5w0rd) with the text hidden but still have functionality (by that i mean be able to type manually afterwards) of the CMD prompt window. Is this at all possible? Many thanks for looking. VP Link to comment Share on other sites More sharing options...
vestanpance3110 Posted July 19, 2019 Author Share Posted July 19, 2019 Does anyone have any suggestions at all..? Thanks in advance. Link to comment Share on other sites More sharing options...
Nine Posted July 19, 2019 Share Posted July 19, 2019 (edited) make your run without /k or /c and use @SW_HIDE : Local $pid = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED) once you get the result, remove the password off the string...if you are showing it to user... Edited July 19, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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