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

When using telnet client, after using .exec command, I want to press enter key, but don't know how to do this. #212

Open
Usama10020 opened this issue Jun 1, 2022 · 4 comments

Comments

@Usama10020
Copy link

Usama10020 commented Jun 1, 2022

Hello, I am trying to connect to a router that is running on gns3 using telnet. After successful connection i want to execute some commands and want to press enter key after each command.

here is my code:

const myFunc = async () => {
  const connection = new Telnet();

  // these parameters are just examples and most probably won't work for your use-case.
  const params = {
    host: "localhost",
    port: 5000,
    shellPrompt: ">", // or negotiationMandatory: false
    timeout: 1500,
  };

  try {
    await connection.connect(params);
  } catch (error) {
    // handle the throw (timeout)
    console.log(`error: ${error}`);
  }

  const res = await connection.exec("enable");

  //here i want to press enter key

  const res1 = await connection.exec("show running-config", {
    shellPrompt: "#",
  });
  
  //here i want to press enter key
  console.log(`res1: ${res1}`);
};

After running this code, it successfully connects to router and then run the first command enable.
image_2022-06-02_013420133

But it is not sending the enter key that why i receive the error:
image

Please guide me, how to resolve the issue.

@mkozjak
Copy link
Owner

mkozjak commented Jun 1, 2022

Tried sending \r\n or some other line terminator to the telnet session?

@Usama10020
Copy link
Author

Tried sending \r\n or some other line terminator to the telnet session?

I tried it, but giving the same error.

@Usama10020
Copy link
Author

Tried sending \r\n or some other line terminator to the telnet session?

Hello brother, i am waiting for your response.

@mkozjak
Copy link
Owner

mkozjak commented Jun 4, 2022

To be honest, it would be the best to tcpdump both sessions (your code and a regular telnet cli command that works) and see the differences.

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

No branches or pull requests

2 participants