Connection to the Router via nodeJS / Telnet

Hi,
I’m hope having found the right place for my questionin this forum, if not please excuse me…

My goal:
I’m trying to change the hotspot user password via telnet in nodeJS.

My router version:
v6.22.1.

My problem:
In nodeJS I use the telnet-client package from https://github.com/mkozjak/node-telnet-client to connect to my router and then to change the password of a specific hotspot user.
As I can see in the log entries on the router, I get connected but can’t change the password. My command looks like this:
cmd = “/ip hotspot user edit hotspotname password CTRL-K newpassword CTRL-O”;
Question 1: What are CTRL-K and CTRL-O telnet-commands?
Question 2: Is it possible to send the command in one single line or do I have to send “sleep” commands after password (see cmd =…)? The reson why I’m asking Question 2 is that I successfully changed the password via putty and at that step one gets the vi-like editor where one sees the password and can change it via CTRL-K and save it via CTRL-O.

Is there a code example for changing the hotspot user password via telnet?

regards
K.

Why use telnet to begin with? You can use the API protocol for that instead. There’s a NodeJS API client you can use.

With the API protocol, you can easily do the change, and check that it succeeded.

i tried node.js Api. as example i can view ip address in terminal by running node js code. but i want to run node js script on click html button.
var api = require(‘mikronode’);

var connection = new api(‘192.168.5.1’,‘admin’,‘admin@123’);
connection.connect(function(conn) {

var chan=conn.openChannel();

chan.write('/ip/address/print',function() {
   chan.on('done',function(data) {

      var parsed = api.parseItems(data);

      parsed.forEach(function(item) {
         console.log('Interface/IP: '+item.name+"/"+item.address);
      });

      chan.close();
      conn.close();

   });
});

});

Thank you very much. It seems to be the better way. I’ll give it a try.
Regards

Thanky you Tiran. I’ll check it out.
Regards

Now I’m using mikronode, what really feels better then telnet. Unfortunately I’m getting a timeout error. Here is my Code:

    myConn.connect(function (conn) {

[font=Courier New][/font]
[font=Courier New]        var kanal = conn.openChannel();[/font]
[font=Courier New]        conn.closeOnDone = true;[/font]
[font=Courier New]        kanal.write(['/ip/hotspot/user/edit/hotspot_name/', '=password=XXXXX'], function () {[/font]
[font=Courier New]            kanal.closeOnDone = true;[/font]
[font=Courier New]            kanal.on('done', function (data) {[/font]
[font=Courier New]                var parsed = MikroNode.parseItems(data);[/font]
[font=Courier New]                parsed.forEach(function (item) {[/font]
[font=Courier New]                    console.log('Ergebnis: ' + item);[/font]
[font=Courier New]                });[/font]
[font=Courier New]            });[/font]
[font=Courier New]            kanal.once('trap', function (trap, chan) {[/font]
[font=Courier New]                console.log('Befehl fehlgeschlagen: ' + trap);[/font]
[font=Courier New]            });[/font]
[font=Courier New]            kanal.once('error', function (err, chan) {[/font]
[font=Courier New]                console.log('Oops: ' + err);[/font]
[font=Courier New]            });[/font]
[font=Courier New][/font]
[font=Courier New]            kanal.close();[/font]
[font=Courier New]            myConn.close();[/font]
[font=Courier New][/font]
[font=Courier New]        });[/font]
    });

What am I doing wrong?

Use the “set” command instead. Also, when using the API, be aware of unnamed arguments.

If you’re at a terminal, and type a command, you can then press “?” to see all arguments. Unnamed arguments are written surrounded with “<” and “>”. f.e. most “set” commands have “< numbers >”, meaning that “/ip hotspot set username password=xxx” is the same as “/ip hotspot set numbers=username password=xxx”. You can omit “numbers=” in terminal, but you can’t do that with the API, so:

['/ip/hotspot/user/set', '=numbers=hotspot_name', '=password=XXXXX']

Thanks Boen.
I’ve solved the problem and can set the password now.