0

I've encountered quite a strange phenomenon; when using the client.RunCommand() function, I get the entire output from the switch, but when using my own implementation:

SshClient cl = new SshClient(ip, username, password);

cl.Connect();

shell = cl.createShellStream("Tail", 80, 24,800, 600, 1024);

StreamWriter wr = new StreamWriter(shell);
StreamReader rd = new StreamReader(shell);

wr.AutoFlush = true;

wr.WriteLine("show int status");

string rep = shell.Expect("Switch_Wan#", new TimeSpan(0,0,3));
MessageBox.Show(rep, "Output");

I only get partial output, and a prompt saying --More--. How can I get the entire output from the switch?

An example for the partial output:

show int status

Port    Name        Status  Vlan    Duplex  Speed   Type
Fa0/1   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/2   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/3   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/4   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/5   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/6   Team7       disabled    97  auto    auto    10/100BaseTX
Fa0/7   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/8   Team7       connected   97  a-full  a-100   10/100BaseTX
Fa0/9   Team11      connected   11  a-full  a-100   10/100BaseTX
Fa0/10  Team11      connected   11  a-full  a-100   10/100BaseTX
Fa0/11  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/12  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/13  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/14  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/15  Team4       disabled    94  auto    auto    10/100BaseTX
Fa0/16  Team11      connected   11  a-full  a-100   10/100BaseTX
Fa0/17  Team11      connected   11  a-full  a-100   10/100BaseTX
Fa0/18  Team11      connected   11  a-full  a-100   10/100BaseTX
Fa0/19  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/20  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/21  Team4       connected   94  a-full  a-100   10/100BaseTX
Fa0/22  Team4       connected   94  a-full  a-100   10/100BaseTX
--More--
Switch_Wan#

While using the client.RunCommand() function, I get the entire 48 ports in the output.

I can't use client.RunCommand(), I must use streams.

What is the meaning of the values that go into cl.CreateShellStream("Trail", 80, 24,800, 600, 1024);?

3 Answers 3

2

Here's a shot in the dark... try this:

shell = cl.createShellStream("Tail", 0, 0, 0, 0, 1024)

I'm still new to SSH.NET, but I think this essentially sets your shell window size to infinite and so less/more does not come into play.

Sign up to request clarification or add additional context in comments.

Comments

2

Just run "term len 0" at the start of your session and you can avoid the --More-- prompts altogether

1 Comment

this is the real answer
1

EDIT: Adam Shortland gave a better answer: term len 0 Found the solution, but forgot to come back and answer. SNMP (2nd option) is still a valid solution and you can use it to get a lot mor information, but for this question, the correct answer is the one by Adam.

This looks similar to what I was working on recently. While Simon's answer will give you more data, it won't help if return more data than the shell size (e.g. if you have a big switch with a lot of ports).

There are two ways I tried to solve this:

  1. read the latest line and check for presence of --More--

Problem with this is that based on the software version of the switch, this format was different. So this broke my usage.

  1. The 2nd and better option for me was using SNMP to get this information.

If you just want information from a switch, I'll definitely use SNMP rather than SSH. All this information is very easy to obtain if you have the correct OIDs. You'll need to do a SNMP walk to get this information. The library I used is SNMP#NET

As for the values that go into CreateShellStream method, here is the method declaration from the docs: public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.