send enable command to Cisco router with enabl - WeOnlyDo Discussion board

send enable command to Cisco router with enabl (wodWebServer / wodWebServer.NET)

by eltaghi, Saturday, April 08, 2006, 13:42 (6596 days ago)

When I send the command enable to Cisco router via web-console using wodSSH.net COM, I get the following:
myhost>enable
Password:
Access denied

The cursor is not waiting to send the password.
Any Idea?
OR How can I send enable command and enable password to access privilege mode after successful connection?

Re: send

by wodDrazen, Saturday, April 08, 2006, 15:24 (6596 days ago) @ eltaghi

Hi Eltaghi,


You can try something like this:

-----------
ssh1.WaitFor ( regex:[$ #>] $ )
Debug.Print ssh1.Execute( enable & vbLf, Password: )
ssh1.Send ( your_password & vbLf)
-----------

Hope I helped.


Regards,
Drazen

Re: send

by eltaghi, Saturday, April 08, 2006, 16:57 (6596 days ago) @ wodDrazen

I used C# as follows:
------
try
{
Ssh1.WaitFor( regex:[$ #>] $ );
Ssh1.Execute( enable\r\n , Password: );
Ssh1.Send( mypassword\r\n );
outputTxt.Text = receiveLast();
}
catch (Exception ex)
{
outputTxt.Text = ERROR: + ex.Message;
}
---
But I get :
ERROR: Timeout occurred due to inactivity.
=====
Thanks for your quick response.

Re: send

by woddrazen, Saturday, April 08, 2006, 17:35 (6596 days ago) @ eltaghi

Hi Eltaghi,

I reply also to your ticket question, did you get that e-mail reply?

Regards,
Drazen

Re: send

by eltaghi, Saturday, April 08, 2006, 17:48 (6596 days ago) @ woddrazen

Yes, But it is just a link to this post.

Re: send

by woddrazen, Saturday, April 08, 2006, 17:58 (6596 days ago) @ eltaghi

Eltaghi,

I was thinking, did you get email to your yahoo e-mail.

Drazen

Re: send

by eltaghi, Saturday, April 08, 2006, 18:07 (6596 days ago) @ woddrazen

No. I have been opening my Yahoo account, but no mail comes from you.

Re: send

by wodDrazen, Saturday, April 08, 2006, 18:48 (6595 days ago) @ eltaghi

Hi Eltaghi,


You code looks fine to me, first you wait for prompt that comes and then send your Command, wait for Password prompt and after that put password.
What is prompt that your server will give your after sending password.
Can you determine where exactly in which line your code stops working so we can duplicate it.
Also did you set blocking property = true (Ssh1.Blocking = True) before calling Connect Method.

Best option to solve your problem is to send us your information with name of server, login and password so we can connect there and duplicate your problem.
You can send it to techsupport@weonlydo.com

Hope I helped.


Regards,
Drazen

Re: send

by wodSupport, Saturday, April 08, 2006, 22:34 (6595 days ago) @ wodDrazen

Eltaghi,

your code looks ok to me, with small change - Cisco may be VERY sensitive about it. Don't send \r\n, send only \n .

When it doesn't work, at which line in your code does it stop? How far is your code executed nicely?

Kreso

Re: send

by eltaghi, Saturday, April 08, 2006, 23:39 (6595 days ago) @ wodSupport

I think I should implement the event PromptReceivedEvent to be fired when the prompt Password: received from the server. So I need help to do this.
-------
Note:
1. Blocking is set to true.
2. The prompt expected after enable command is Password: .
3. The prompt expected after sending the password is myhost# . (My Objective)
4. The router (ie. server) is connected to my PC (Web Server). So you can not access the router directly, because I don't have Static IP. You can access it via the page: http://eltagi.dyndns.org/securerouter.
5. The connection established properly, and the server replied with:
myhost>
6. But the error Timeout occurred due to inactivity. received from the server when the following code is executed:
Ssh1.WaitFor( regex:[$ #>] $ );
Ssh1.Execute( enable\n , Password: );
Ssh1.Prompt = Password: ;
//Ssh1.Send( thePassword\n );
receiveLast();

Thanks

Re: send

by wodDrazen, Saturday, April 08, 2006, 23:47 (6595 days ago) @ eltaghi

Hi Eltaghi,

Did you read and try last post that Kreso send you?

--------------
Eltaghi,

your code looks ok to me, with small change - Cisco may be VERY sensitive about it. Don't send
, send only
.

When it doesn't work, at which line in your code does it stop? How far is your code executed nicely?

Kreso
---------------

Drazen

Re: send

by wodDrazen, Monday, April 10, 2006, 13:11 (6594 days ago) @ wodDrazen

Eltaghi,


Here is code which you can try it:

---------------------------
Ssh1.WaitFor( regex:[$ #>] $ );
Ssh1.Execute( enable
, Password: );
Ssh1.Send( mypassword
);
outputTxt.Text = Ssh1.WaitFor( regex:[$ #>] $ );
---------------------------


I need you to run this code with break point(line by line) and determine which is exactly line where error occur.
This is very important for helping you and for trying to resolve your problem.
Can you try this?


Regards,
Drazen

Re: send

by eltaghi, Tuesday, April 11, 2006, 07:54 (6593 days ago) @ wodDrazen

Dear Drazen,

1- All these issues are considered. I know that when I send
in this post It appears only n. But it is considered in the code.

2- I have two buttons in my app. One to connect and the other is to enable privilege mode. the connect button establiched the connect properly (and Blocking is set to true). The code which you sent I put it in the enable button .

3- first I click the Connect button, which produces the output :
myhost>
4- Then if I clicked the Enable Button I get the error:
Timeout occured due to inactivity.

Thanks

Re: send

by woddrazen, Tuesday, April 11, 2006, 10:01 (6593 days ago) @ eltaghi

Hi Eltaghi,


Here is corected code:

---------------------------
Ssh1.Blocking = True
Ssh1.Connect

Ssh1.WaitFor( regex:[$ #>] $ );
Ssh1.Execute( enable\n , Password: );
Ssh1.Send( mypassword\n );
outputTxt.Text = Ssh1.WaitFor( regex:[$ #>] $ );
---------------------------

Sorry my mistake I didn't tell you that you need set Blocking Property to True(Ssh1.Blocking = True) and I see that I send you enablen and I mean enable\n and mypasswordn and I mean mypassword\n .

Can you try that code with break point and tell us what is the line where it fals.


Regards,
Drazen

Re: send

by eltaghi, Tuesday, April 11, 2006, 10:10 (6593 days ago) @ woddrazen

Dear Drazen,

1- All these issues are considered. I know that when I send \n in this post It appears only
. But it is considered in the code.

2- I have two buttons in my app. One to connect and the other is to enable privilege mode. the connect button establiched the connection properly (and Blocking is set to true). The code which you sent I put it in the enable button .

3- first I click the Connect button, which produces the output :
myhost>
4- Then if I clicked the Enable Button I get the error:
Timeout occured due to inactivity.

Thanks

Re: send

by wodSupport, Tuesday, April 11, 2006, 11:56 (6593 days ago) @ eltaghi

Let me try to hop in and help.

We need to isolate where exactly your code fails. If I understood correctly, you connect fine, and you're given a prompt. Now you do this:[code]Ssh1.Execute( enable\n , Password: );[/code]Does your code fail here? If you step by step through the code, does it return from here?

If it doesn't return, then it means that 'Password:' prompt was never received from the server. In that case you must isolate the error and see *what was returned* instead of 'Password:', for example like this:[code]Ssh1.Send( enable\n );Msgbox Ssh1.Receive();[/code]Now what was shown as received data? YOu must adjust Execute method call so it does detect received data.

Reason why you get Timeout error is because wodSSH doesn't find what it expected to find, but if we don't have access to your device then you must figure out why this happens. Can you try above and tell me *exactly* what is received after sending 'enable' command?

If you can set up access to the device, that would be appreciated. You can send details to techsupport@weonlydo.com

Kreso

Re: send

by eltaghi, Tuesday, April 11, 2006, 16:03 (6593 days ago) @ wodSupport

I love you Drazen
I love you Kreso
I love all of you WODSSH.net
It is working with the following code:
-----
Ssh1.Send( enable\n );
Ssh1.Send( enablePassword\n );
outputTxt.Text += receiveLast();
-----
Please check the website: http://eltagi.dyndns.org/securerouter/
-----

Up to now we are fine and it will be so fine if you help to do the following:
1. When I issue command like show run the data received partially; so I need to send space bar to the router to receive the next patch.
2. Also if I want to cancel receiving data, I need to send CTRL+C .
How can I do these.
----eg: start here ---------
myhost#sh run
Building configuration...

Current configuration : 2387 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname myhost
!
aaa new-model
!
!
aaa authentication login default enable
aaa authentication enable default enable
aaa authorization exec default none
aaa session-id common
enable secret 5 $1$m3Jx$1s5vUR1fkW7zFtxH0rw9v1
enable password xxxxxx
!
username uuuu password 0 pppp
mmi polling-interval 60
no mmi auto-configure
no mmi pvc
--More--
myhost#
----------- eg: end here ------------

As you see --More-- indicate that there is more data to receive, so to get these data we should press space bar, or in our case send space bar to the router.
This is my code to implement this:
Ssh1.Send( \n );
outputTxt.Text += receiveLast();
But it is not responding. (Help is needed here).

Note that from the show run output, we saw the phrase myhost# immediatley after --More--. It should not appear if there is more data to receive.

Thanks


Re: send

by wodDrazen, Tuesday, April 11, 2006, 17:18 (6593 days ago) @ eltaghi

Eltaghi,


You can try send CTRL+C on this way:

Ssh1.Send (CHR$(3));


I hope this will work. You need to wait for prompt --More-- and you need to send space bar \n , here is how:

Ssh1.WaitFor( --More-- );
Ssh1.Send( \n );


Drazen

Re: send

by wodDrazen, Tuesday, April 11, 2006, 21:11 (6592 days ago) @ wodDrazen

Eltaghi,


Before you send command show run you can send command terminal length 0 this is command is Cisco which disable need to press space for the next page.
Can you try it?


Drazen

Re: send

by eltaghi, Tuesday, April 11, 2006, 23:07 (6592 days ago) @ wodDrazen

Dear Drazen,

For CTRL+C:
Ssh1.Send(CHR$(3)); produce err: myhost>HR$(3)
Ssh1.Send( ^ ); is escaping, but disconnected the conn.
Ssh1.Send( \b ); is also escaping, but disconnected the conn.
I think there is a special character for that.

For space bar:
//Ssh1.WaitFor( --More-- ); working when this line is ignored.
Ssh1.Send( \n ); this line working fine to get the next data

Thanks

Re: send

by wodDrazen, Tuesday, April 11, 2006, 23:55 (6592 days ago) @ eltaghi

Eltaghi,

Did you try this?
Before you send command show run you can send command terminal length 0 this is command is Cisco which disable need to press space for the next page.


Drazen

Re: send

by wodSupport, Wednesday, April 12, 2006, 00:36 (6592 days ago) @ wodDrazen

Eltaghi,

I double-checked, you must send chr$(3) to the server. I'm not sure which programming language you use. If it's wodSSH.NET, then code like this should do it:[code]Dim b(0) As Byte
b(0) = 3
Ssh1.Send(b)[/code]Can you try that?

Kreso


Re: send

by eltaghi, Wednesday, April 12, 2006, 07:22 (6592 days ago) @ wodSupport

Dear Drazen,
Now space bar is working fine.
Only CTRL+C is remaining.

Dear Kreso,
I am using asp.net project with c# as code behinde (and offcourse the WODSSH.net COM with LICENSE).

Thanks

Re: send

by wodSupport, Wednesday, April 12, 2006, 16:13 (6592 days ago) @ eltaghi

Eltaghi,

then above code must work - I tested it. In C# it would be something like this:[code]byte[] b = new byte[1];
b[0] = 3;
wodSSH.Send(ref b);
[/code]


Can you try that and tell me what happens?

BTW, if I may have an opinion, I think this is wrong approach. I don't think you should send CTRL+C at all. I would personally find cleaner way to solve those ---More--- lines, such as with 'terminal length 0' command, or using Receive method inside a loop...

Kreso

Re: send

by eltaghi, Wednesday, April 12, 2006, 20:06 (6591 days ago) @ wodSupport

Hello Kreso,
Your Code is working fine:
----------------------
byte[] b = new byte[1];
b[0] = 3;
Ssh1.Send( b );
-------------Thanks---------
Also, sending:
Ssh1.Send( \b );
OR
Ssh1.Send( ^ );
Do the same job. I found some code that call Ssh1.Receive after disconnection, so I thought it was from Ssh1.Send( \b ); or Ssh1.Send( ^ );.
--------------------
Now I have two issues:

1. Some times when I click the GO Button to send a command, I did not get the response, but when I click for the second time I get the response twice. That means the first command sent properly.

2. I would like to use or understand the use of:
* WaitFor method
* Prompt property
* PromptReceivedEvent
To be used in this scenario:
------------:
The More Button is disabled by default. So when the prompt --More-- received from the server, the More Button should go enabled.

Thanks

Re: send

by wodSupport, Wednesday, April 12, 2006, 22:13 (6591 days ago) @ eltaghi

I don't know about 'more' buttons since I don't have full overview in your code, but what you described that happens could be explained that you didn't wait for some prompt. Did you?

If I were you, I wouldn't use Prompt property and PromptReceived event at all - don't mix those with WaitFor/Execute in blocking mode. So, in those methods always specify pattern that should be received.

I'd like to see your full code, and hopefully connect to same server if possible, to see what's troubling you. Would this be possible? Can you send me that to techsupport@weonlydo.com ?

Kreso

Re: send

by eltaghi, Wednesday, April 12, 2006, 23:21 (6591 days ago) @ wodSupport

Dear Kreso,

I sent the whole project. If you need more info about the router and the web server let me know.

Thanks