|
Secure iNet Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jscape.inet.telnet.Telnet
com.jscape.inet.telnetssh.TelnetSsh
public class TelnetSsh
Implements the basic functionality of a Telnet client as defined in RFC 854 tunnelling all data thru a secure SSH connection. This class requires that BOTH the telnet and SSH services be enabled on the host machine and that port forwarding be enabled. For a SSH client that does not require port forwarding see the com.jscape.inet.ssh.Ssh class.
Upon establishing a connection the Telnet server may attempt to perform option negotiation (see RFC 855). Any optionnegotiation options exchanged must be handled prior to receiving a login or shell prompt.
To handle option negotiation you must add a TelnetListener to the Telnet instance and overload the doOption, dontOption, willOption and wontOption methods.
Once option negotiation has completed sucessfully a separate thread is spawned that reads data sent by the Telnet server. You can capture this data by overloading the dataReceived method in the TelnetListener interface or TelnetAdapter class.
See the Ssh
class to interact with a remote shell without port forwarding thru
the Telnet service. Use of this class requires that the Telnet service be enabled on the remote host.
Example Usage:
public class TelnetExample extends TelnetAdapter { private TelnetSsh telnet = null; private OutputStream output = null; private static BufferedReader reader = null; private boolean connected = false; private String hostname = "10.0.0.1"; private String sshHostname = "10.0.0.1"; private String sshUsername = "jsmith"; private String sshPassword = "secret"; private SshParameters sshParams = null; public TelnetExample() throws IOException, TelnetException { // create SSH connection parameters sshParams = new SshParameters(sshHostname,sshUsername,sshPassword); // create new TelnetSsh instance telnet = new TelnetSsh(sshParams,hostname); // register this class as TelnetListener telnet.addTelnetListener(this); // establish Telnet connection telnet.connect(); connected = true; // get output stream output = telnet.getOutputStream(); // sends all data entered at console to Telnet server String input = null; while ((input = reader.readLine()) != null) { if (connected) { ((TelnetOutputStream) output).println(input); } else { break; } } } // Invoked when Telnet socked is connected. public void connected(TelnetConnectedEvent event) { System.out.println("Connected"); } // Invoked when Telnet socket is disconnected. Disconnect can public void disconnected(TelnetDisconnectedEvent event) { connected = false; System.out.print("Disconnected. Press enter key to quit."); } // Invoked when Telnet server requests that the Telnet client begin performing specifiedTelnetOption
. public void doOption(DoOptionEvent event) { // refuse any options requested by Telnet server telnet.sendWontOption(event.getOption()); } // Invoked when Telnet server offers to begin performing specifiedTelnetOption
. public void willOption(WillOptionEvent event) { // refuse any options offered by Telnet server telnet.sendDontOption(event.getOption()); } // Invoked when data is received from Telnet server. public void dataReceived(TelnetDataReceivedEvent event) { // print data recevied from Telnet server to console System.out.print(event.getData()); } // starts console program public static void main(String[] args) { try { // create BufferedReader to read data from console reader = new BufferedReader(new InputStreamReader(System.in)); // create new TelnetExample instance TelnetExample example = new TelnetExample(); } catch (Exception e) { e.printStackTrace(System.out); } } }
Ssh
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class com.jscape.inet.telnet.Telnet |
---|
Telnet.ByteDecoder, Telnet.DefaultDecoder, Telnet.EUCKoreanDecoder, Telnet.UTF8Decoder |
Field Summary |
---|
Fields inherited from class com.jscape.inet.telnet.Telnet |
---|
COMMAND_MAP, TC_AO, TC_AYT, TC_BRK, TC_DM, TC_DO, TC_DONT, TC_GA, TC_IP, TC_NOP, TC_SB, TC_SE, TC_WILL, TC_WONT, TSC_BEL, TSC_BS, TSC_CR, TSC_EC, TSC_EL, TSC_FF, TSC_HT, TSC_IAC, TSC_LF, TSC_NULL, TSC_VT |
Constructor Summary | |
---|---|
TelnetSsh(SshParameters sshParameters,
java.lang.String hostname)
Creates a new TelnetSsh instance. |
Method Summary | |
---|---|
void |
connect()
Establishes connection with SSH server and creates secure tunnel to Telnet server. |
void |
disconnect()
Closes tunnel to Telnet server and closes connection with SSH server. |
SshParameters |
getSshParameters()
Gets SSH parameters used in establishing connection with SSH server. |
void |
setSshParameters(SshParameters parameters)
Sets SSH parameters used in establishing connection with SSH server. |
Methods inherited from class com.jscape.inet.telnet.Telnet |
---|
addTelnetListener, clearProxySettings, getCharacterSet, getCommandName, getDebug, getDebugStream, getHostname, getInputStream, getOutputStream, getPort, getReader, getTimeout, getWriter, removeTelnetListener, sendCommand, sendCommand, sendDontOption, sendDoOption, sendOptionSubnegotiation, sendWillOption, sendWontOption, setCharacterSet, setDebug, setDebugStream, setHostname, setPort, setProxyAuthentication, setProxyHost, setProxyType, setTimeout |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TelnetSsh(SshParameters sshParameters, java.lang.String hostname)
hostname
- sshParameters
- Method Detail |
---|
public void connect() throws TelnetException
connect
in class Telnet
TelnetException
- if an I/O or Telnet related error occurspublic void disconnect()
disconnect
in class Telnet
public SshParameters getSshParameters()
SshParameters
public void setSshParameters(SshParameters parameters)
parameters
- the SSH parametersSshParameters
|
Secure iNet Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |