Ive 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.
Thanks in advanced, if anything is not clear, please say so.
ps. before anyone suggests, no, i cant use client.RunCommand()
, i must use streams.
pps if anyone could explain the values that go into cl.CreateShellStream("Trail", 80, 24,800, 600, 1024);
i would be very very thankful as i dont really understand what those values go into
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.
Just run "term len 0" at the start of your session and you can avoid the --More-- prompts altogether
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 (eg if you have a big switch with a lot of ports).
There are two ways I tried to solve this:
Problem with this is that based on the software version of the switch, this format was different. So this broke my usage.
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 SNMPSharp.NET ( http://www.snmpsharpnet.com/ )
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.