How to disable echo when sending a terminal command using apache-commons-net TelnetClient

前端 未结 6 1258
醉梦人生
醉梦人生 2020-12-11 03:10

So, I have this class that uses the org.apache.commons.net.telnet.TelnetClient class. It attempts to send commands and read the response.

public class Automa         


        
6条回答
  •  时光取名叫无心
    2020-12-11 03:43

    Interesting problem. To summarize my effort: I didn't get it working properly But here are some of my findings:

    You cannot write IAC DON'T ECHO directly to the data channel, this is done with commands and options like this example

    int[] msg = {TelnetCommand.DONT,TelnetOption.ECHO};
    telnet.sendSubnegotiation(msg);
    

    You can register telnet.registerNotifHandler(new MyNotificationHandler()); to debug the commands during connection setup

    public class MyNotificationHandler implements TelnetNotificationHandler
    {
      @Override
      public void receivedNegotiation(int negotiation_code, int option_code)
      {
        System.out.println("--->"+get(negotiation_code)+" "
                                 +TelnetOption.getOption(option_code));
      }
    
      private String get(int i)
      {
        if(i==TelnetNotificationHandler.RECEIVED_DO){return "RECEIVED_DO";}
        else if(i==TelnetNotificationHandler.RECEIVED_DONT){return "RECEIVED_DONT";}
        else if(i==TelnetNotificationHandler.RECEIVED_WILL){return "RECEIVED_WILL";}
        else if(i==TelnetNotificationHandler.RECEIVED_WONT){return "RECEIVED_WONT";}
        else if(i==TelnetNotificationHandler.RECEIVED_COMMAND)
                                                        {return "RECEIVED_COMMAND";}
        return "UNKNOWN";
        }
    }
    

提交回复
热议问题