Example: /Network/SSH/SSH tunnel connection

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/Network/SSH/SSH tunnel connection


Required plugins for this example: MBS Network Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Network/SSH/SSH tunnel connection

This example is the version from Fri, 4th Mar 2021.

Project "SSH tunnel connection.xojo_binary_project"
Class App Inherits ConsoleApplication
Const kenn = ""
EventHandler Function Run(args() as String) As Integer const Address = "1.2.3.4" const username = "xxx" const password = "yyy" const keyfile1 = "" const keyfile2 = "" dim hostAddr as string = System.Network.LookupIPAddress(Address) print hostAddr //* Create a session instance and start it up. This will trade welcome //* banners, exchange keys, and setup crypto, compression, and MAC layers dim session as new MySSH2SessionMBS(hostAddr, 22) session.MyPassword = password if session.Handle = 0 then print "Failed to connect socket!" Return 1 end if session.SessionHandshake if session.lasterror<>0 then print "Failure establishing SSH session" Return 9 end if //* At this point we havn't authenticated. The first thing to do is check //* the hostkey's fingerprint against our known hosts Your app may have it //* hard coded, may go to a file, may present it to the user, that's your //* call dim fingerprint as string = session.HostKeyHash(session.kHostKeyHashSHA1) print "Fingerprint: "+EncodeHex(fingerprint) //* check what authentication methods are available */ dim userauthlist as string = session.UserAuthList(username) dim authPassword as Boolean = false dim authKeyboardInteractive as Boolean = false dim authPublickey as Boolean = false print "Authentication methods: "+ userauthlist if instr(userauthlist, "password")>0 then authPassword = true end if if instr(userauthlist, "keyboard-interactive")>0 then authKeyboardInteractive = true end if if instr(userauthlist, "publickey")>0 then authPublickey = true end if if authPassword then //* We could authenticate via password */ session.UserAuthPassword(username, password) if session.LastError = 0 then // ok print "Authentication by password succeeded." else // failed print "Authentication by password failed!" Return 1 end if elseif authKeyboardInteractive then //* Or via keyboard-interactive */ session.UserAuthKeyboardInteractive username if session.LastError <> 0 then print "Authentication by keyboard-interactive failed!" return 10 else print "Authentication by keyboard-interactive succeeded." end if //* Or by public key */ elseif authPublickey then session.UserAuthPublicKeyFromFile(username, keyfile1, keyfile2, password) if session.LastError <> 0 then print "Authentication by public key failed!" Return 4 else print "Authentication by public key succeeded." end if else print "No supported authentication methods found!" Return 3 end if // here we are authorized //* Open tunnel */ dim tunnel as new SSH2TunnelMBS(session) tunnel.LocalAddress = "127.0.0.1" tunnel.LocalPort = 8000 tunnel.RemoteAddress = "monkeybreadsoftware.de" tunnel.RemotePort = 80 // avoid timeing out in Socket and SSH layers tunnel.KeepAlive = True session.ConfigureKeepAlive // run it tunnel.Run // while it runs, connect to our website through port 8000 // don't alter session while tunnel runs do app.DoEvents 10 loop until not tunnel.Running print tunnel.Messages session.Disconnect "Normal Shutdown, Thank you for playing" session = nil print "done" Return 0 End EventHandler
End Class
Class MySSH2SessionMBS Inherits SSH2SessionMBS
EventHandler Sub KeyboardCallback(Name as string, Instruction as string, PromptCount as integer, Prompts() as SSH2UserAuthKeyboardInteractivePromptMBS, responses() as SSH2UserAuthKeyboardInteractiveResponseMBS) print "Name: "+Name print "Instruction: "+Instruction for each p as SSH2UserAuthKeyboardInteractivePromptMBS in Prompts print p.Text next if PromptCount = 1 then responses(0).Text = MyPassword end if End EventHandler
Property MyPassword As string
End Class
End Project

See also:

The items on this page are in the following plugins: MBS Network Plugin.


💬 Ask a question or report a problem