Jump to content

Recommended Posts

Posted

I am launching PuTTY via my script.

$PuTTYcmd = @ScriptDir & "\testing\puttyportable\puttyportable.exe -l " & $myLogin & " -load " & $txtENV

The server automatically authenticates the user. So, no password is needed. After logging in, the user is presented with a numbered list of options. I want to be able to 'read' that screen and make a selection for them. To do this I need the contents of that screen copied to the clipboard. Manually clicking on the title bar and selecting 'Copy All to Clipboard' technically works, but I want to eliminate the need for user intervention.

I have searched the forum and haven't found anything particularly helpful in my situation.

Is it possible to pull/read the screen contents of a PuTTY session using AutoIt?

Posted

I think there was a Function to read other Forms and they Labels etc..

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Posted

If i would know the Function i would say it but i forgot it but maybe you could look at the locked threads with game Automation mostly there would be maybe the Function you are seeking for~

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Posted

Do you need the users to see or interact with putty at all? I tried reading the output of the GUI version of putty years ago and couldn't get it to work, but I was able to get the CLI version, plink, to work with reading and interacting with the output using StdoutRead. Here is basically what I used many years ago for running a bunch of commands on Cisco switches

$IP = "192.168.5.5"
$UName = "user"
$UPass = "pass"
$ENPass = "enpass"

$PID = _Connect($IP)
If $PID = False Then
    MsgBox(0, "Login Error", "Error logging into device: " & $IP, 8)
    Exit
EndIf
If _Enable($PID) = False Then Exit MsgBox(0, "Priv EXEC Error", "Error going into privilege EXEC mode on: " & $IP, 8)

Local $OUT, $aTask[1] = ["Task"]
_FileReadToArray(@ScriptDir & "\Commands.txt", $aTask)
For $t = 1 To UBound($aTask) - 1
    $OUT2 = _Task($PID, $aTask[$t])
    If StringInStr($OUT2, "Task Error") Then
        $OUT &= @CRLF & "~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF & "Error executing: " & $aTask[$t] & @CRLF & $OUT2 & @CRLF & "~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF
        ExitLoop
    EndIf
    $OUT &= $OUT2
Next

Func _Connect($cIP)
    Local $cOUT = ""
    $cPID = Run(@ScriptDir & "\plink.exe -ssh -l " & $UName & " -pw " & $UPass & " " & $cIP, @DesktopDir, @SW_HIDE, 0x1 + 0x8)
    For $c = 1 To 45
        Sleep(100)
        $cOUT = StdoutRead($cPID)
        If StringInStr($cOUT, ">") Then
            Return $cPID
        ElseIf StringInStr($cOUT, "Store key") Then
            StdinWrite($cPID, "y" & @CRLF & @CRLF)
            Sleep(2000)
            $cOUT = StdoutRead($cPID)
            If StringInStr($cOUT, ">") Then
                Return $cPID
            Else
                Return False
            EndIf
        ElseIf StringInStr($cOUT, "Update cached") Then
            StdinWrite($cPID, "y" & @CRLF & @CRLF)
            Sleep(2000)
            $cOUT = StdoutRead($cPID)
            If StringInStr($cOUT, ">") Then
                Return $cPID
            Else
                Return False
            EndIf
        EndIf
    Next
    Return False
EndFunc   ;==>_Connect

Func _Enable($ePID)
    Local $eOUT = ""
    StdinWrite($ePID, "enable" & @CR & $ENPass & @CRLF)
    Sleep(1000)
    $eOUT = StdoutRead($ePID)
    If StringInStr($eOUT, "#") Then
        StdinWrite($ePID, "terminal length 0" & @CR & @CRLF)
        Sleep(250)
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_Enable

Func _Task($tPID, $tTask)
    Local $tOUT = ""
    StdinWrite($tPID, $tTask & @CR)
    Sleep(100)
    For $t = 1 To 80
        Sleep(100)
        $tOUT &= StdoutRead($tPID)
        If StringInStr(StringRight($tOUT, 1), "#") Then
            Sleep(100)
            Return $tOUT
        EndIf
    Next
    Return "Task Error" & @CRLF & $tOUT
EndFunc   ;==>_Task

 

Posted

Baraoic, Yes, I will need the user to interact with putty. The initial screen that displays for them gives them an option of what environment they want to log into. I want to 'automate' that menu screen and make the selection for them. The rest of the session the user will be interacting with putty.

Posted (edited)

SuperPutty FTW :)

Being as how I saw you mention the copy all to clipboard feature, I came up with this.  Though its totally not a "good" way to do it as it uses clicks and sends and such, but hey you can try it and see if it works for you.

;Press Control+Alt+p to get Current Putty Screen Text
HotKeySet("^!p", "PuttyScreen")

While 1
    Sleep(10)
WEnd

Func PuttyScreen()
$aOldMouse = MouseGetPos()
$vOldClip = ClipGet()
WinActivate("[REGEXPTITLE:PuTTY.*]", "")
$aPos = WinGetPos("[REGEXPTITLE:PuTTY.*]", "")
MouseClick("left", $aPos[0]+15, $aPos[1]+15, 1, 1)
Send("{DOWN 13}{Enter}")
$vClip = ClipGet()
ClipPut($vOldClip)
MouseMove($aOldMouse[0], $aOldMouse[1], 1)
MsgBox(0, "", "Current PuTTY Window:" & @CRLF & @CRLF & $vClip)
EndFunc

 

Edited by ViciousXUSMC

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
  • Recently Browsing   0 members

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