Recieving data from ssh login to Mikrotik host fa - WeOnlyDo Discussion board

Recieving data from ssh login to Mikrotik host fa (General questions)

by johnboy, Wednesday, April 05, 2006, 17:00 (6807 days ago)

Hi supportforum,

we are using the following software:

wodSSH.Net v. 2.2.1.50
.Net Framework 2.0 / Visual Basic 2005 Express Edt.
Mikrotik RouterOS 2.9.18 (www.mikrotik.com)

The task is to connect to the Mikrotik, execute commands and get the
result back. Example with PuTTY:

[code]
login as: admin
admin@xxx.xxx.xxx.xxx password:

MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK
MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK

MikroTik RouterOS 2.9.18 (c) 1999-2006 http://www.mikrotik.com/


Terminal xterm detected, using multiline input mode
[admin@Hotspot] > /system clock print
time: 15:43:26
date: apr/05/2006
time-zone: +01:00
dst-active: no
[admin@Hotspot] >
[/code]

I used the following code:

[code]
Ssh.Login = admin
Ssh.Password = xxxxxxxx
Ssh.Encryption = WeOnlyDo.Client.SSH.EncryptionMethods.Auto
Ssh.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto
Ssh.Blocking = True
Ssh.Prompt = regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $
Ssh.Connect( xxx.xxx.xxx.xxx )
Ssh.WaitFor( regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $ )
Ssh.Receive()

result = Ssh.Execute( /system clock print & vbCrLf, regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $ )
Ssh.Receive()

Console.Write(result)
[/code]

execution of these lines returns

[code]
[admin@Hotspot] >


[admin@Hotspot] >
[/code]

Mikrotik uses the following SSH server:
[code]
[root@telefonzelle ~]# ssh -2 -v admin@xxx.xxx.xxx.xxx
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_2.3.0_Mikrotik_v2.9
debug1: match: OpenSSH_2.3.0_Mikrotik_v2.9 pat OpenSSH_2.3.0*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client 3des-cbc hmac-md5 none
debug1: kex: client->server 3des-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD(2048) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'xxx.xxx.xxx.xxx' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_dss_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
admin@xxx.xxx.xxx.xxx's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.

MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO O

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 17:03 (6807 days ago) @ johnboy

There are missing the last lines from my posting !!??

They just said if anybody has an idea to fix this problem ??

Thanks

Johnboy

Re: Recieving data from ssh login to Mikrotik hos

by wodDrazen, Wednesday, April 05, 2006, 19:02 (6806 days ago) @ Johnboy

Hi Johnnyboy,,


Could you try with this code.
Did you recive something in debug mode?

-------------
Set ssh1 = New wodSSHCom
ssh1.HostName = your.hostname
ssh1.Protocol = SSHAuto
ssh1.Blocking = True
ssh1.Login = admin
ssh1.Password = xxxxxx
ssh1.Prompt = regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $
ssh1.Connect

ssh1.Send ( /system clock print & vbCrLf)
Debug.Print ssh1.Receive
ssh1.Disconnect
------

Let me know how it goes.


Regards,
Drazen

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 19:08 (6806 days ago) @ wodDrazen

I tested ...

[code]
Ssh.Login = admin
Ssh.Password = xxxxxx
Ssh.Encryption = WeOnlyDo.Client.SSH.EncryptionMethods.Auto
Ssh.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto
Ssh.Blocking = True
Ssh.Prompt = regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $
Ssh.Connect( xxx.xxx.xxx.xxx )

Ssh.Send( /system clock print & vbCrLf)
Debug.Print(Ssh.Receive())
[/code]

it runs without errors, but produces no output ...

What to try now ?

Johnboy

Re: Recieving data from ssh login to Mikrotik hos

by wodDrazen, Wednesday, April 05, 2006, 19:11 (6806 days ago) @ Johnboy

Hi Johnnyboy,


Are you sure you didn't receive in debug mode?

----------
[admin@Hotspot] > /system clock print
time: 15:43:26
date: apr/05/2006
time-zone: +01:00
dst-active: no
[admin@Hotspot] >
-----------


Regards,
Drazen

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 19:15 (6806 days ago) @ wodDrazen

My Debug window in Visual Studio stays empty ...


Johnboy

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 19:25 (6806 days ago) @ Johnboy

Tried something more:

[code]
Ssh.Login = admin
Ssh.Password = xxxx
Ssh.Encryption = WeOnlyDo.Client.SSH.EncryptionMethods.Auto
Ssh.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto
Ssh.Blocking = True
Ssh.Prompt = regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $
Ssh.Connect( kronsberg-bw.xxx.xxxx )
Console.WriteLine(Ssh.Execute( & vbCrLf, regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $ ))
Ssh.WaitFor( regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $ )
Ssh.Receive()

Console.WriteLine(Ssh.Execute(vbCrLf & /system clock print & vbCrLf, regex:[[a-z]+@[a-zA-z]+][a-zA-z0-9 ]+> $ ))
Ssh.Receive()
CloseSSHConnection()
[/code]

produces the following console output:

[code]

MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK
MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK

MikroTik RouterOS 2.9.18 (c) 1999-2006 http://www.mikrotik.com/


Terminal vt100 detected, using single line input mode

[admin@Hotspot] >


[admin@Hotspot] >


[admin@Hotspot] >

[/code]

Does this help ???

Johnboy

Re: Recieving data from ssh login to Mikrotik hos

by wodDrazen, Wednesday, April 05, 2006, 19:27 (6806 days ago) @ Johnboy

Johnboy


I tested on server demo.mt.lv and it works for me and result is same as yours with putty.
Could you send us your login and password and hostname that you are connecting so we can try to duplicate your problem over here.
You can send it to techsupport@weonlydo.com is this possible?

Hope I helped.


Drazen

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 19:34 (6806 days ago) @ wodDrazen

I will send you the account details via email ....


Johnboy
--

Re: Recieving data from ssh login to Mikrotik hos

by Johnboy, Wednesday, April 05, 2006, 20:06 (6806 days ago) @ Johnboy

Your are right, I tested my code with demo.mt.lv and it worked !! same output like in Putty!

I did some more tests and found out one funny thing ...
this code produces nothing:


[code]
Console.WriteLine(Ssh.Execute( /system clock print & vbCrLf, regex:[[a-z]+@[a-zA-z.]+][a-zA-z0-9 ]+> $ ))
Ssh.Receive()
[/code]

This code:

[code]
Console.WriteLine(Ssh.Execute( /system clock print & vbCrLf, regex:[[a-z]+@[a-zA-z.]+][a-zA-z0-9 ]+> $ ))
Ssh.Receive()

Console.WriteLine(Ssh.Execute( /system clock print & vbCrLf, regex:[[a-z]+@[a-zA-z.]+][a-zA-z0-9 ]+> $ ))
Ssh.Receive()
[/code]

produces this:
[code]
[demo@Hotspot] >

/system clock print
[demo@Hotspot] > /system clock print
time: 19:01:26
date: apr/05/2006
time-zone: +01:00
dst-active: no

[demo@Hotspot] >
[/code]

and so on ... 3 times execute produces 2 times output and so on ... he always loses the last command result ...

I have always tested it with one execute, so it looses it !!! Becaouse of that I got no output so far ...

But why does it works with demo.mt.lv ... same Mikrotik version ... or where is the data resultset for the last command execute ??

Johnboy

[code][/code]

Re: Recieving data from ssh login to Mikrotik hos

by wodDrazen, Wednesday, April 05, 2006, 20:14 (6806 days ago) @ Johnboy

Johnboy,


Can you try something like this(instead semding vbCrlf send vbLf):


---------------
Console.WriteLine(Ssh.Execute( /system clock print & vbLf, regex:[[a-z]+( at )[a-zA-z( point )]+][a-zA-z0-9 ]+> $ ))
Ssh.Receive()
---------------


Drazen