Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection.exec is appending extra characters #164

Open
nigilan opened this issue Apr 8, 2020 · 3 comments
Open

connection.exec is appending extra characters #164

nigilan opened this issue Apr 8, 2020 · 3 comments

Comments

@nigilan
Copy link

nigilan commented Apr 8, 2020

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
Copy link

wensonH commented Aug 10, 2020

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
Copy link
Owner

mkozjak commented Mar 12, 2021

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

@nigilan
Copy link
Author

nigilan commented Mar 12, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants