Grab telnet window text
Moderators: Dorian (MJT support), JRL
Grab telnet window text
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
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
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]
[email protected]
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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).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.
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
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com
Why not use the built-in telnet capabilities of Macro Scheduler
like this example illustrates?
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
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.
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
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com
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.
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.
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.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.
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
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com
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?
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
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
OH, THAT'S JUST BEAUTIFUL.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
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
LIS System Analyst, Children's Hospital, Columbus, Ohio
Web Pages:
http://www.LorenceSing.com
http://LorencesKitchen.Blogspot.com