1

I am working with a Numato relay, and I try to connect to it via telnet using javascript with net.Socket, and then send commands.

However, when trying to connect, it rejects the username and password. The problem is that strange characters are entered after entering the username.

In the code you can see that I tried to look at the outputs in various ways, with no results.

If anyone knows why or has worked with Numato modules I would appreciate any help. Here is the code and its output:

    var net = require('net');

    var client = new net.Socket();

    client.connect(23, '192.168.1.100', function() {
      console.log('Connected');
    });
    client.on('connect', function(){
      client.write('admin\n')
      client.write('admin\n')
      // client.write('admin\n' + 'admin\n')
    })

    client.on('data', function(data) {
      console.log(''+data)
      // var datos = []
      // datos.push(data)
      // datos.push(data.toJSON)
      // console.log(datos)
      // client.destroy(); // kill client after server's response
    });

    client.on('close', function() {
      console.log('Connection closed');
    });

Output img

Dominik
  • 6,078
  • 8
  • 37
  • 61
Strife52
  • 11
  • 1

2 Answers2

0

According to the Numato documentation this channel requires ASCII character encoding rather than the UTF encoded strings you are sending.

Change:

    client.on('connect', function(){
      client.write('admin\n')
      client.write('admin\n')
      // client.write('admin\n' + 'admin\n')
    })

To:

    client.on('connect', function(){
      client.write('admin\n', 'ascii')
      client.write('admin\n', 'ascii')
      // client.write('admin\n' + 'admin\n')
    })

NOTE: eol's answer is likely applicable here too. If you are on Windows(assumed here), the you'll need both \r\n.

Randy Casburn
  • 13,840
  • 1
  • 16
  • 31
  • Hi Randy, thank you very much for your help. Tried what you suggested and also modifying the "setEncoding" globally. Also, I tried all possible encoding combinations of the message and the global one, and changing the carriage return (\ r \ n). In the output only the characters changed, but they are still intrusive characters. I think the problem must be so small that I can't see it. – Strife52 Nov 08 '20 at 12:59
0

I had similar issues when I tried to communicate to a telnet server through NodeJS. What solved my problem was to use an carriage return before the line feed character:

client.write('admin\r\n');
eol
  • 23,236
  • 5
  • 46
  • 64
  • How does that explain the "_strange characters_" the OP points out and show in the image. – Randy Casburn Nov 05 '20 at 21:07
  • Maybe because the sent data is misinterpreted because of the incorrect line endings, it was pretty much the same in my case. But of course - encoding could be an issue as well as you wrote.. – eol Nov 05 '20 at 21:13
  • Hi Eol, thanks for your suggestion. I tried, but the result is the same. I keep investigating. – Strife52 Nov 08 '20 at 13:01