AutoIt
AutoIt
SSH Tunnel Through an Outbound SOCKS Proxy
See more SSH Tunnel Examples
Demonstrates reaching the SSH server through an outbound SOCKS proxy using the SocksVersion, SocksHostname, SocksPort, SocksUsername, and SocksPassword properties.
Background: This is the reverse direction from dynamic forwarding: here a SOCKS proxy is used to reach the SSH server, for networks where outbound connections must pass through one.
SocksVersion is the switch — 0 means no SOCKS, while 4 or 5 selects the protocol. SOCKS5 supports username/password authentication and remote DNS; SOCKS4 supports only a username.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates reaching the SSH server through an outbound SOCKS proxy using the SshTunnel
; properties SocksVersion, SocksHostname, SocksPort, SocksUsername, and SocksPassword.
$oTunnel = ObjCreate("Chilkat.SshTunnel")
; Set SocksVersion to 4 or 5 to route the outbound connection to the SSH server through a SOCKS
; proxy. A value of 0 (the default) means no SOCKS proxy.
$oTunnel.SocksVersion = 5
$oTunnel.SocksHostname = "socks.example.com"
$oTunnel.SocksPort = 1080
; SOCKS4 supports only a username; SOCKS5 supports username and password.
$oTunnel.SocksUsername = "myProxyLogin"
$oTunnel.SocksPassword = "myProxyPassword"
$oTunnel.DestHostname = "db.internal.example.com"
$oTunnel.DestPort = 5432
; Connect to the SSH server through the SOCKS proxy configured above.
Local $iSshPort = 22
$bSuccess = $oTunnel.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf
; Normally you would not hard-code the password in source. You should instead obtain it
; from an interactive prompt, environment variable, or a secrets vault.
Local $sPassword = "mySshPassword"
$bSuccess = $oTunnel.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf
Local $iListenPort = 1080
$bSuccess = $oTunnel.BeginAccepting($iListenPort)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Tunnel established through the SOCKS proxy." & @CRLF)
Local $bWaitForThreadExit = True
$bSuccess = $oTunnel.CloseTunnel($bWaitForThreadExit)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf