mkozjak / node-telnet-client

A simple telnet client for Node.js
Other
347 stars 97 forks source link

connection.exec is appending extra characters #164

Open nigilan opened 4 years ago

nigilan commented 4 years ago

I am having this piece of code for sending commands to a machine.

import Telnet from 'telnet-client';

const connectionForAPI = new Telnet();

export default function sendCommand() {
  const params = {
    host: '192.168.XX.XX',
    port: 23,
    shellPrompt: '',
    timeout: 1500,
  };

  connectionForAPI.connect(params);

  connectionForAPI.on('ready', (prompt) => {
    setInterval(() => {
      const bufStr = '\xaa\x23\x64\xcd\x00\x0e\x09\xa0\xa2\x06ABCDE\x0d';
      const buf = Buffer.from(bufStr, 'ascii');
      console.log('buff', buf);
      connectionForAPI.exec(buf);
    }, 1000);
  });
}

While the console is giving me the expected output I need aa 23 64 cd 00 0e 09 a0 a2 06 41 42 43 44 45 0d, when I watch the data being sent in wireshark it is different like ef bf bd 23 64 ef bf bd 00 0e 09 ef bf bd ef bf bd 06 41 42 43 44 45 0d 0a.

Any idea why the data is changed after it went through .exec(). Any suggestions will be helpful, thanks in advance.

wensonH commented 4 years ago

exec() will append '\n' to your executing cmd, if you want avoid this behavior, you can add 'ors' option(defualt '\n') in your connect params, Unfortunaly. when you do this, you will login fail. because ors(default '\n') also use at login process. maybe you should change the source code

mkozjak commented 3 years ago

@wensonH @nigilan maybe have any PRs that fix this issue?

nigilan commented 3 years ago

I moved to 'net' module from telnet-client.