Jump to content

TeraTerm with varibles from CMD


Recommended Posts

Dear forum members,

 

I am trying to create a script that will allow me to launch ttermpro.exe (telnet client) via Autoit.

I was able to get this working by using the following:

Global $ip
$ip = '192.168.1.11'
$username = 'telnet'
$pwd = 'Aa123456'

#RequireAdmin
Run(@ScriptDir &'\ttermpro.exe')
AutoItSetOption('MouseCoordMode',0)

WinWait('Tera Term: New connection')
WinActivate('Tera Term: New connection')
MouseClick('primary', 198, 101, 1, 0)
WinWait('Tera Term: New connection')
MouseClick('primary', 295, 55, 1, 0)
ControlSend('Tera Term: New connection','', '', ""& $ip & "")
MouseClick('primary', 146, 260, 1, 0)
WinWait($ip & " - Tera Term VT")
ControlSend($ip & " - Tera Term VT", "", "", $username & "{ENTER}")
ControlSend($ip & " - Tera Term VT", "", "", $pwd & "{ENTER}")

 

However, it means that I will have to hardcode $ip, $username and $pwd, and that is not something I would like to do.

I would like to run it from cmd similar to the following:

test 192.168.1.1 telnet Aa123456

and to have these paremeters map to $ip,$username,$hostname 

 

How can I accomplish this?

 

Thanks,

Kelso

 

Link to comment
Share on other sites

  • Moderators

@kelso TeraTerm comes with a ton of built in command line options, with a pretty good reference sheet on their website (just Google TeraTerm command line). Have you tried this yet, to save yourself the headache of the MouseClick method?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

5 minutes ago, JLogan3o13 said:

@kelso TeraTerm comes with a ton of built in command line options, with a pretty good reference sheet on their website (just Google TeraTerm command line). Have you tried this yet, to save yourself the headache of the MouseClick method?

Thanks for your reply.

Yes I am aware that there are better ways than mouse clicks and I plan on translating it to something better.

I just want to have POC with mouse clicks as it's the easiest thing I saw in the guide books.

The only missing piece of the puzzle is how do I feel the variables using cmd line.

 

Link to comment
Share on other sites

Ok so I took your comments, change the method to Putty and it looks like the following:

$ip = '192.168.1.11'
$username = 'telnet'
$pwd = 'Aa123456'
$port = ':23'

Run(@ScriptDir &'\putty.exe telnet://' & $ip & $port)
WinWait($ip & " - PuTTY")
ControlSend($ip & " - PuTTY", "", "", $username & "{ENTER}")
ControlSend($ip & " - PuTTY", "", "", $pwd & "{ENTER}")

works great, now I just need to figure out how I can fetch the parameters of ip,username  and pwd from command line, any suggestions?

Link to comment
Share on other sites

  • Moderators

You could create a small gui around the script, allowing the user to enter username and password. Something like this, perhaps:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $sUserName, $sPassword

$hGUI = GUICreate("TeraTerm", 300, 500)
    GUISetState(@SW_SHOW)
    GUISetFont(11, 400, Default, "Arial")

    $lblUserName = GUICtrlCreateLabel("Username", 115, 10, 65, 30)
    $lblPassword = GUICtrlCreateLabel("Password", 115, 90, 150, 30)
    $lblVerify = GUICtrlCreateLabel("Verify Password", 95, 170, 150, 30)
    $lblIP = GUICtrlCreateLabel("IP Address", 105, 250, 150, 30)
    $lblPort = GUICtrlCreateLabel("Port", 115, 330, 150, 30)

    $inpUserName = GUICtrlCreateInput(@UserName, 10, 40, 280, 30, $ES_CENTER)
    $inpPassword = GUICtrlCreateInput("", 10, 120, 280, 30, $ES_PASSWORD)
    $inpVerify = GUICtrlCreateInput("", 10, 200, 280, 30, $ES_PASSWORD)
    $inpIP = GUICtrlCreateInput("", 10, 280, 280, 30)
    $inpPort = GUICtrlCreateInput("", 10, 360, 280, 30)

    $btnGo = GUICtrlCreateButton("Connect", 10, 450, 125, 35)
    $btnClose = GUICtrlCreateButton("Exit", 165, 450, 125, 35)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $btnClose
                ExitLoop
            Case $btnGo
                If GUICtrlRead($inpPassword) == GUICtrlRead($inpVerify) Then
                    $sUserName = GUICtrlRead($inpUserName)
                    $sPassword = GUICtrlRead($inpPassword)
                    $sIP = GUICtrlRead($inpIP)
                    $sPort = GUICtrlRead($inpPort)
                    _connectPutty($sUserName, $sPassword, $sIP, $sPort)
                Else
                    MsgBox(0, "TeraTerm", "Passwords do not match!")
                EndIf
        EndSwitch
    WEnd

Func _connectPutty($Username, $Password, $IP, $PortNum)
    Run(@ScriptDir &'\putty.exe telnet://' & $IP & $PortNum)
    WinWait($IP & " - PuTTY")
    ControlSend($IP & " - PuTTY", "", "", $Username & "{ENTER}")
    ControlSend($IP & " - PuTTY", "", "", $Password & "{ENTER}")
EndFunc

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Usually for scripts that need user input on each run I start with a simple InputBox() for testing, once that is working the way I want, I go retrofit the script with a GUI instead.

My favorite program is Putty but specifically I really like Super Putty, once taken the time to build my folder tree for my  network infrastructure I can connect/find anything pretty fast and easy.

So it holds all my switch names/locations/ip addresses, and I can just script my PW to an auto fill hotkey for faster entry.

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...