IPWorks SSH 2020 JavaScript Edition

Questions / Feedback?

RequestForwarding Method

Requests the server to forward a remote TCP/IP port.

Syntax

async sshreversetunnel.requestForwarding(address : string, port : number, forwardingHost : string, forwardingPort : number): Promise<void>

Remarks

The RequestForwarding method asks the server to listen at the specified TCP/IP Address and Port for connection requests and then forward them as new SSH channels to the class.

ForwardingHost and ForwardingPort may be used to specify an address and port to which traffic will automatically be forwarded. If automatic forwarding is not desired specify an empty string ("") for the ForwardingHost parameter.

The Address argument can specified in different ways:

  • "" means that connections are to be accepted on all protocol families supported by the server.
  • "0.0.0.0" means to listen on all IPv4 addresses.
  • "::" means to listen on all IPv6 addresses.
  • "localhost" means to listen on all protocol families supported by the SSH implementation on loopback addresses only.
  • "127.0.0.1" and "::1" indicate listening on the loopback interfaces for IPv4 and IPv6, respectively.

Passing a value of 0 for the Port parameter instructs the server to assign a port. In this case, query the ForwardedPort setting to determine the port that was assigned by the server.

The class has two modes that allow data to be dealt with directly from the events, or automatically forwarded on to a different endpoint.

Event Based Operation

In this mode any data received by the class over the tunnel causes the events of the class to fire. For instance:


SSHReverseTunnel.RequestForwarding("0.0.0.0",777,"",0);

In the above code forwarding is request from port 777 on the SSHHost. Any data received on port 777 by the SSHHost will be sent to the class. In the above code the last two parameters are empty or 0 indicating to the class that no local forwarding is requested.

Once RequestForwarding returns the SSH reverse tunnel is established and any connection made to the SSH host on the specified port will trigger events of the class to fire allowing you to handle the connection request and data.

When a client connects to the SSH host on the specified port the SSHChannelOpenRequest event will fire. Within this event choose to accept or reject the connection by setting the e.Accept parameter. This event contains details about the connection that may be used when determining whether to accept the connection.

After the channel is established data is received through the SSHChannelData event. To send data over the channel call the SendChannelData method. To close the channel call the CloseChannel method.

Local Forwarding

In this mode the any data received by the class is automatically forwarded to a separate endpoint. This allows the class to act as a sort of proxy. There is no need to handle data directly in this case. For instance:

SSHReverseTunnel.RequestForwarding("0.0.0.0",777,"nsoftware.com",80);

In the above code forwarding is request from port 777 on SSHHost. The class is instructed to establish a connection to "nsoftware.com" on port 80 when a client connect to SSHHost on port 777. Any data received from the client connected to SSHHost on port 777 will automatically be forwarded to "nsoftware.com" on port 80. Any data received back from "nsoftware.com" on port 80 will be sent back to the connected client.

In this mode data may flow freely from the client connected to the SSHHost to the endpoint specified in the RequestForwarding method without any additional code required.

Copyright (c) 2023 /n software inc. - All rights reserved.
IPWorks SSH 2020 JavaScript Edition - Version 20.0 [Build 8501]