How to login into Telnet without user name

+1 vote
asked Nov 20, 2014 by sujayghosh (360 points)
edited Nov 25, 2014

Hello

I have a device , which does not have a user name. I am mentioning the steps below; which I follow , using Putty.

  1. Specify ip address and choose Telnet as an option.
  2. The terminal screen appears, with the normal prompt.
  3. Enter the first level password , to gain access
  4. Enter the command "enable" without quotes
  5. Enter the second level password, to gain access to the elevated prompt
  6. The screen can be found at http://ctrlv.in/463900

I see all the examples in Rebex requires a login name, but in the above case no user name is required.

Please let me know how can I achieve the above situation using Rebex.

Thanks Sujay

1 Answer

0 votes
answered Nov 21, 2014 by Pavel Matyska (10,840 points)
edited Nov 25, 2014
 
Best answer

Hello,

our samples contains login name requests because most of servers need it and send a request to enter the login name. Since your server does not need it, you can skip that step and make the Password: as your first step. Here is a code snippet that shows how to handle the screen you posted above.

Telnet telnet = new Telnet("server");
Scripting scripting = telnet.StartScripting();

// password prompt is not a regular prompt
scripting.ReadUntil("Password:");
// send first level password
scripting.SendCommand("first level password");

// here I believe that detect prompt can be used,
// or if you know that you will immediately send "enable" command
// you can read the prompt as a required text and not bother
// to set it as a prompt
scripting.ReadUntil("first level prompt"); // which ends with ">"

// if you connect to various devices with same behaviour but different
// prompt, but you want to skip to setsetting the first level prompt as
// discussed above, you can change ReadUntil argument to some regular
// expression

// uncomment this line if a regular expression is better way
// to handle various devices with different (but similar) prompts
// and comment out the 'scripting.ReadUntil("first level prompt");' line
// make sure that the regular expression describe your prompts correctly
//scripting.ReadUntil(ScriptEvent.FromRegex("[a-zA-Z0-9]+>");

// when you have first level prompt, send "enable" command
scripting.SendCommand("enable");

// password prompt is not a regular prompt, same as at the beginning
scripting.ReadUntil("Password:");
// send second level password
scripting.SendCommand("second level password");

// now detect prompt should work.
scripting.DetectPrompt();

// since you may be using your own detect prompt you may need
// to call it instead of a rebex`s DetectPrompt
// DetectPrompt(scripting);

// do the work here...
commented Nov 24, 2014 by sujayghosh (360 points)
edited Nov 24, 2014

Many thanks, it worked.

...