cadpnq / telnetlib

A simple Node.js telnet server/client library.
MIT License
18 stars 2 forks source link

disable echo #1

Open voidest1 opened 3 years ago

voidest1 commented 3 years ago

This project is perfect to me, thanks a lot. I created a server by telnetlib. I want disable client echo the password input, but didn't work. Finally I found the solution, client.enableRemote(1) can hide type from client. But I want recover to normal echo, I called client.disableRemote(1) was catch the exception. Who can help me?

voidest1 commented 3 years ago

I tried any ways, finally it is working. disable echo: client.writer.writeDo(1) enable echo: client.writer.writeWont(1) I don't know why but it is worked.

cadpnq commented 3 years ago

Hello, I'm glad that you figured something out on your end, but this still sounds like something that needs looked at. Would it be possible for you to share a cut down version of your code that shows the weird behavior?

voidest1 commented 3 years ago

sure.:-) The following is the code for hide client's type, the comments is old that. ` hideInput(){

  (async()=>{
      // await this.client.enableRemote(1);
      this.client.writer.writeDo(1);
      this.passInput = true;
  })();
}

`

the next is the code for recover to normal echo. ` netClient.on('data', (msg)=>{

            if(self.passInput) {
                self.passInput = false;
                (async()=>{
                       //await self.client.disableRemote(1); //here raise an exception
                })();
                self.client.writer.writeWont(1);
            }
            if(self.onMessage){
                self.onMessage(msg.toString());
            }
        });

`

eirikb commented 2 years ago

I want something similar, I want to detect when echo is disabled, is this possible? I need to look for IAC + WILL + 1. I noticed client.options.keys will contain 1, but not if it was enabled or disabled.

eirikb commented 2 years ago

I think I found a solution, something like this:

const { ECHO } = telnetlib.options;

const c = telnetlib.createConnection(
  {
    host: "aardwolf.org",
    port: 23,
    remoteOptions: [ECHO],
  },
  () => {
    c.on("enable", (option) => {
      if (option === ECHO) {
        // Enable password
      }
    });
    c.on("disable", (option) => {
      if (option === ECHO) {
        // Disable password
      }
    });
  }
);