我telnet到我的思科设备,一切正常,使用TCPClient思科响应字节数组我可以得到和编码到字符串。
发送和接收工作正常,我收到思科响应我的RichtextBox的所有内容..
问题:我不知道如何显示端口状态,端口数量并将它们加载到TextBox,Combobox。
无论如何获得端口数并获取其状态然后显示到WinForm中的Control(例如在Listview中)。
当我运行'show ip int bri'
时,我的Richtextbox已经返回FastEthernet0/1 unassigned YES unset up up
FastEthernet0/2 unassigned YES unset down down
FastEthernet0/3 unassigned YES unset down down
FastEthernet0/4 unassigned YES unset down down
FastEthernet0/5 unassigned YES unset down down
FastEthernet0/6 unassigned YES unset down down
FastEthernet0/7 unassigned YES unset down down
FastEthernet0/8 unassigned YES unset down down
FastEthernet0/9 unassigned YES unset down down
--More-- FastEthernet0/10 unassigned YES unset down down
FastEthernet0/11 unassigned YES unset down down
FastEthernet0/12 unassigned YES unset down down
这是按钮显示端口
private void btnShowPort_Click(object sender, EventArgs e)
{
try
{
serverStream = clientSocket.GetStream();
if (serverStream.CanWrite)
{
txtOutput.Enabled = true;
byte[] outStream2 = System.Text.Encoding.ASCII.GetBytes("sh ip int br" + "\n"+" ");
serverStream.Write(outStream2, 0, outStream2.Length);
serverStream.Flush();
}
else
{
MessageBox.Show("Server is not connected!");
clientSocket.Close();
serverStream.Close();
return;
}
if (serverStream.CanRead)
{
AutoCloseMsgBox.Show("Show Port...", "Thong Bao", 1200);
byte[] inStream = new byte[clientSocket.ReceiveBufferSize];
serverStream.Read(inStream,0,(int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
Msg(returndata);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return;
}
}
我的Richtextbox显示思科发送信息
public void Msg(string msg)
{
this.txtOutput.Text = txtOutput.Text + msg;
this.txtOutput.Text = txtOutput.Text.Replace("????????","Welcome Telnet Management");
}