Jump to content

Sending data to CMD Window using Stdin


Recommended Posts

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

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 by Nine
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...