Sign in to follow this  
Followers 0
LGC

Using AutoIt to control putty

8 posts in this topic

putty is a telnet client, although I'm sure most of you know that.

You input the ip address of the computer your sending the commands to, and putty opens a window that is named " 'ip address' - putty "

That would be fine if I was using the script for one ip address but i am not.

I was thinking that autoit can ask me for the ip address then use the ip address I input to launch putty and also use the ip address as a variable to control the window, but I can't figure out how to do that.

here are some screen caps from putty so that you can get a better idea:

Posted Image

Posted Image

Posted Image

Only problem is, I don't know how to do that. lol.

Any help would be appreciated.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

One way to do it is log onto the system and allow putty to accept the key. Afterwards the authentication box will no longer appear. I have scripted a few AutoIT scripts because we do a lot of remote administration of Unix systems and use putty on a daily basis with dozens of different servers.

Func do_backup()
    Send("cd dba ; tail `ls -tr *backup* | tail -1` | (grep Finished && ls -ltr *backup*) || (tail -f `ls -tr *backup* | tail -1`){ENTER}")
EndFunc

Func get_idpw()
#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

    GuiCreate("Enter ID/Password", 197, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

    $Input_id = GuiCtrlCreateInput("Input1", 80, 20, 110, 20)
    $Label_2 = GuiCtrlCreateLabel("ID", 10, 20, 40, 20)
    $Label_3 = GuiCtrlCreateLabel("Password", 10, 50, 60, 20)
    $Input_pw = GuiCtrlCreateInput("Input4", 80, 50, 110, 20)
    $Button_5 = GuiCtrlCreateButton("OK", 50, 80, 60, 20)

    GuiSetState()
    While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        case $msg = $Button_5
            ExitLoop
        Case Else
            ;;;
        EndSelect
    WEnd

    $id = GUICtrlRead($Input_id)
    $pw = GUICtrlRead($Input_pw)
    
    GUIDelete()

#endregion --- GuiBuilder generated code End ---

EndFunc

Func send_idpw()
    Send( $id & "{ENTER}" )
    Sleep (3000)
    Send( $pw & "{ENTER}" )
    Sleep (3000)
EndFunc

Of course this only works when the putty window is active, next step is to incorporate plink into AutoIT.

Edited by cpuobsessed

Share this post


Link to post
Share on other sites

my sample, not read window..... conect on

$user = "root"
$password =""
$host ="5.0.0.1"
$port ="22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script

; putty -ssh -l usuario 5.0.0.1 p "port" -pw senha

;input

$command = RunWait(@comspec & " /C "&$puty_exe&" -ssh -l "&$user&" "&$host&" p "&$port&" -pw "&$password,@ScriptDir, @SW_HIDE, 1)
;$command = RunWait(@comspec & " /C "&$puty_exe&" system scripts run mario",@ScriptDir, @SW_HIDE, 1)
While 1
$data = StdoutRead($command)
ConsoleWrite($data&@CRLF)
If @error Then ExitLoop
Wend

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Share this post


Link to post
Share on other sites

God save the resurrection.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

bhns, please don't necro-post, this thread is almost 6 years old.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

thx bhns!

I was looking for this!

btw, what's wrong with posting in such old topics that turn up as first result upon a google search "autoit putty" ?

Share this post


Link to post
Share on other sites

tito,

We ask peopel not to necro-post for two main reasons:

- 1. The language advances and the functionality might well be included in core or UDF code by now.

- 2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.

Clear enough? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0