mkozjak / node-telnet-client

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

Help set up the connection #240

Open MGMehdi opened 6 months ago

MGMehdi commented 6 months ago

Hello,

I try to set up the package for a simple connection without login. I've try some example but it seem that the connection doesn't work. The code have to work on Windows and the connection is working using the telnet client feature.

Here is the code

import { Telnet } from "telnet-client";
const connection = new Telnet();

// these parameters are just examples and most probably won't work for your use-case.
const params = {
  host: "192.168.10.112",
  port: 4567,
  negotiationMandatory: false,
};

connection.on("ready", (prompt) => {
  console.log("prompt", prompt);

  connection.exec(cmd, (err, response) => {
    console.log("rep", response);
  });
});

connection.on("timeout", () => {
  console.log("socket timeout!");
  connection.end();
});

connection.on("close", () => {
  console.log("connection closed");
});

connection.connect(params);

And here is the result

socket timeout!
connection closed

Thanks