Jump to content
Macro Express Forums

Need help with Telnet Session Macro


tarunp
 Share

Recommended Posts

I have written a script which opens a telnet session with my router, enters the login and password and then reboots the router. Most of the time this works perfectly but sometimes it takes longer for the login prompt to appear and hence the text is typed too early and the process fails.

 

My question is , what is the command script in Macro Express which would enable me to wait for the login prompt in the telnet window before typing in the text ? How can I ensure that the macro "reads" what is appearing in the telnet window ?

 

I would be grateful for any help on this issue.

Link to comment
Share on other sites

I have written a script which opens a telnet session with my router, enters the login and password and then reboots the router. Most of the time this works perfectly but sometimes it takes longer for the login prompt to appear and hence the text is typed too early and the process fails.

 

My question is , what is the command script in Macro Express which would enable me to wait for the login prompt in the telnet window before typing in the text ? How can I ensure that the macro "reads" what is appearing in the telnet window ?

 

I would be grateful for any help on this issue.

You actually have several options under the Timing category. Wait for Control, Wait for Window Title, Wait for Web Page, but one

option that seems to be successful most often for most people is not a Timing command at all: Get Pixel Color

 

First you want to establish what color the telnet prompt is once it has finished loading. So you can either build a simple macro like this:

 

Get Pixel: Window Coords: 409,313 into %N1%

Text Box Display: Pixel Color

 

(This assumes the prompt or change that tells the macro the telnet page has finished loading is at location 409, 313) Make sure the text

box displays %N1%... that's the color you want to write down.

 

Or you could just launch the Mouse Locator tool (accessible from the Move Mouse command), which can tell you the pixel color

under the mouse pointer.

 

Now for your macro. Where you need the macro to wait, you'll script it something like this:

 

Variable Set Integer %N2% to 123456789
Repeat Until %N1% = %N2%
 Get Pixel: Window Coords: 409,313 into %N1%
Repeat End

 

For my example I set N2 to 123456789 though the color you're waiting for will certainly be different.

 

This code will cause your macro to loop, checking the pixel color at the coordinates you select (409,313 for my example) over and over

until the color matches the color indicating the page is finished loading. At that point, the loop will end and the macro will continue on.

 

There may be a more elegant way of doing this, but this method has been very successful for me when I've need to wait and the wait fors

weren't quite cutting it.

 

Here's the actual code for the script above:

<IVAR2:02:01:123456789><REP3:08:000001:000002:0001:1:01:N2><GETPX:1:W:000409:000313><ENDREP>

Link to comment
Share on other sites

Many thanks for your detailed response. A further question - suppose I wanted the Macro to wait till the following text appeared in the telnet window : "Login Successful" - how would I do that ?

Assuming the "Login Successful" text is in the window title:

Wait For Window Title: "Login Successful"

<WAITWIN2:000010:000000:Login Successful>

 

If the text is only in the body of the window, the macro gets a lot more complicated (consisting of highlighting the entire page, copying it,

saving it to a Text Variable, checking the variable for the text "Login Successful", and then repeating). A Get Pixel Color or other wait-type

command will be considerably less messy.

 

You could, perhaps, view the source and check it for the "Login Successful" text, but again, it will consist of a repeat loop that will be much

less noticeable with a Get Pixel Color command.

 

I suppose it would help if I were a telenet user (or even knew what it was - I'm assuming a dial-up internet service), because then I could

see what the process is actually like and do some tests to find the most efficient method... but as it is, I can only go on my personal

experiences with inconsistent window-loading times. Window Title and Web Page Loading are the two I use most often, but since I started

using Get Pixel Color commands, I've found them to be as effective (more effective when dealing with non-web applications or windows that

have the same title as others open).

 

Another option that I've never used, but may work for you, is the Wait for cursor change command (assuming your mouse pointer

changes from an arrow to an hourglass (or other customized pointers) while the login is in process, and then changes back once the login is

successful.

Link to comment
Share on other sites

Thanks again for your input. A Telnet session opens up a DOS type window where you type in commands to your modem/router. The text displayed is in the window itself and not in the title.

 

I have actually managed a workaround based on some of the hints I got after reading your post.

The telnet session creates and saves a text log file which I have been able to copy to the clipboard and then build it into the macro.

 

Many thanks for your assistance.

Link to comment
Share on other sites

Thanks again for your input. A Telnet session opens up a DOS type window where you type in commands to your modem/router. The text displayed is in the window itself and not in the title.

 

I have actually managed a workaround based on some of the hints I got after reading your post.

The telnet session creates and saves a text log file which I have been able to copy to the clipboard and then build it into the macro.

 

Many thanks for your assistance.

Well, even if I wasn't able to hand it to you baked and frosted, I'm glad I was able to give you a recipe to work with :)

 

(I know, weird cake analogy...)

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...