Grab telnet window text

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Igor77
Newbie
Posts: 2
Joined: Mon Jan 31, 2005 11:33 am

Grab telnet window text

Post by Igor77 » Mon Jan 31, 2005 11:38 am

Hi to everyone, this is my first post :)

I need to capture text (a single word, I mean) in a telnet window, under windows XP.
I wrote a script that telnet to my router Zyxel and I'd like to test and compare some settings variables displayed in the telnet window, so depending on these I can execute the right action.

Is that possibile with Macro Scheduler?

thanks in advice for help

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Jan 31, 2005 12:14 pm

Yes, this is possible, but how you do it depends on which telnet client you are using. Different telnet clients have different ways of selecting text. The simplest thing to do would be to do a select all and copy the text from the entire telnet screen and then extract the portion you require. Some telnet clients provide scripting capabilities which might offer a more elegent solution.
MJT Net Support
[email protected]

Igor77
Newbie
Posts: 2
Joined: Mon Jan 31, 2005 11:33 am

Post by Igor77 » Mon Jan 31, 2005 12:35 pm

That's a good idea.
In my situation, the telnet client is that one embedded with windows xp, and it goes to the Zynos router's software. Unfortunatly I think it hasn't any advanced capabilities.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jan 31, 2005 12:46 pm

Hi,

That's easy:

Press ALT
Send> es
Release ALT
Wait>0.5
Press ALT
Send> ey
Release ALT

ALT-space then e then s selects all the text.
ALT-space then e then y copies it to the clipboard.

Then use GetClipBoard to retrieve the text from the clipboard to a variable and manipulate.

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Post by Lorence » Tue Apr 05, 2011 7:25 pm

mtettmar wrote:Hi,

That's easy:

Press ALT
Send> es
Release ALT
Wait>0.5
Press ALT
Send> ey
Release ALT

ALT-space then e then s selects all the text.
ALT-space then e then y copies it to the clipboard.

Then use GetClipBoard to retrieve the text from the clipboard to a variable and manipulate.
This could work for a project I'm working on, a password reset project. Our application runs via telnet. The user (help desk) will run the compiled macro, which will ask them for the user's access code. It will then lock the keyboard/mouse and run the code to open telnet, login, and open the security function to disply the info for the user they selected. I want to capture that info, close the telnet session, display the user info in a message box asking the user if this is the correct info, unlock the keyboard/mouse and, if they click ok, lock the keyboard and open the session again to reset the password to the default, close the session and unlock the keyboard. If they click no, then it asks them to re-enter the user code (unlocking the keyboard, of course).

My issue has been how to capture the text of the telnet scren (essentially a cmd window) with the keyboard locked and then disply that captureed info to the user. The latter part is what I've been unsure of using the getwindowtext fnction.

This method might work, but will it work witht he keyboard locked?
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Apr 05, 2011 8:14 pm

Why not use the built-in telnet capabilities of Macro Scheduler
like this example illustrates?

Code: Select all

TelnetConnect>my.domain.com,23,hTN
TelnetWaitFor>hTN,Press any key to continue,5,r
TelnetSend>hTN,a
TelnetWaitFor>hTN,login,5,r
TelnetSend>hTN,administrator%CR%
TelnetWaitFor>hTN,password,5,r
TelnetSend>hTN,monsoon%CR%
TelnetWaitFor>hTN,>,5,r
TelnetSend>hTN,dir%CR%
TelnetWaitFor>hTN,>,5,dirlist
MessageModal>dirlist
MessageModal>TELNET_SESSIONLOG
TelnetClose>hTN


Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Post by Lorence » Tue Apr 05, 2011 8:29 pm

The idea is to keep the user locked out of the telnet session other than what the script allows them to enter. The securty that allows them to change passwords unfortunately allows them to do many other admin functions that the ehlp desk filks should NOT be doing and there's no way to split the password change security piece out. I want to get the basic info from them, lock them out, query the system close the system, show them the results and have them verify the results, then, if ok, lock them out again, make the change and close. While the built in telnet would work for the actual entry, I still need to do the text capture. I can't have the session open to them at all.
I have this partially functioning using an AutoIt script but it doesn't do the capture there either, so if they enter the wrong user code to change the password on, there's no check. Also if they enter an invalid code, it tries anyway. Not very clean, so I'm trying to tidy it up.
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

User avatar
JRL
Automation Wizard
Posts: 3503
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Apr 05, 2011 8:44 pm

I sort of wrote a similar script last week. I won't share it but it uses putty and ssh to log into my linux mail server and shut down then restart the virtual server. I used GetWindowTextEx> in a loop then parsed the results to detect how things were progressing and find when to inject commands. I was just thinking today I should block input but so far have not gotten to it.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Apr 05, 2011 10:22 pm

I think the point of my example was missed.

MessageModal>TELNET_SESSIONLOG



Look at the help for the telnet stuff. Macro Scheduler already keeps
a log of everything happening in the telnet session in the TELNET_SESSIONLOG variable.

Why try to automate another external program when this capability is built-in. The telnet screen in Macro Scheduler does not exist, the user can't type anything that you haven't already scripted for them.

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Post by Lorence » Wed Apr 06, 2011 12:28 pm

adroege wrote:I think the point of my example was missed.

MessageModal>TELNET_SESSIONLOG



Look at the help for the telnet stuff. Macro Scheduler already keeps
a log of everything happening in the telnet session in the TELNET_SESSIONLOG variable.

Why try to automate another external program when this capability is built-in. The telnet screen in Macro Scheduler does not exist, the user can't type anything that you haven't already scripted for them.
You are correct, I missed 2 points completely - I didn't know that the user had no access to the telnet session and didn't notice the log. I will attempt this today.

Thanks for your input!
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Post by Lorence » Mon May 23, 2011 5:53 pm

Thanks again for the input above. I've finally gotten a chance to get back to this and your suggestion looks like it could work well.

One further question for you - the information that I need to review in the telnet output will be the tail end. Is there a way to display only the tail end of the telnet_sessionlog information, specifically the last 25 lines? Teh idea is to have the operator review the input and verify that the correct user has been selected for password change. After reviewing and verifying the input, the script will continue, reconnecting using the same input, but completing the password change, again displaying the output for verification purposes.
Is there a way to pipe the telnet_seesionlog through a tail function?
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon May 23, 2011 6:10 pm

So you could just loop through the last n lines:

Code: Select all

Separate>TELNET_SESSIONLOG,CRLF,lines_array
Let>start_line=lines_array_count-25
If>start_line<1
  Let>start_line=0
Endif

Let>output_text=
Let>x=start_line
Repeat>x
  Let>x=x+1
  Let>this_line=lines_array_%x%
  Let>output_text=%output_text%%this_line%%CRLF%
Until>x=lines_array_count

MessageModal>output_text
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Lorence
Newbie
Posts: 11
Joined: Mon Sep 24, 2007 12:34 am
Location: Ohio, USA
Contact:

Post by Lorence » Mon May 23, 2011 6:21 pm

mtettmar wrote:So you could just loop through the last n lines:

Code: Select all

Separate>TELNET_SESSIONLOG,CRLF,lines_array
Let>start_line=lines_array_count-25
If>start_line<1>start_line=0
Endif

Let>output_text=
Let>x=start_line
Repeat>x
  Let>x=x+1
  Let>this_line=lines_array_%x%
  Let>output_text=%output_text%%this_line%%CRLF%
Until>x=lines_array_count

MessageModal>output_text
OH, THAT'S JUST BEAUTIFUL.

it works perfectly. Thanks to all of you, I'm learning so much!
Lorence P. Sing, MT(ASCP)
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts