c# 用telnet 登陆交换机 查询及返回列表

o0冰凉0o o0冰凉0o 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
命令列表:

Password: ****
C1500> enable
Enable Password: ****
C1500# configure terminal
C1500(config)# interface pon 1/1
%Enter configuration commands.End with Ctrl+Z or command "exit" & "end"
C1500(config-if-pon-1/1)#show legal-onu-info
ONU-ID LLID Status MAC address Type Dist(M) ActiveTime
--------------------------------------------------------------------------------
01/01:01 4 online 00:1a:69:7c:27:fd M5-0404E 34 2013/10/24 19:2
2:57
01/01:02 1 online 00:1a:69:7c:27:8d M5-0404E 37 2013/10/24 19:2
2:54
01/01:03 2 online 00:1a:69:78:fc:2b M5-0404E 34 2013/10/24 19:2
3:04
01/01:04 3 online 00:1a:69:7c:28:3f M5-0404E 34 2013/10/24 19:2
3:00
代码:
private void button1_Click(object sender, EventArgs e)
{
Process p = null;
p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "/K start telnet 192.168.8.101";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.OutputDataReceived+=new DataReceivedEventHandler(p_OutputDataReceived);
SendKeys.Send("123456\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("enable\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("123456\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("configure terminal\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("interface pon 1/1\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("show legal-onu-info\r");
System.Threading.Thread.Sleep(800);


p.BeginOutputReadLine();


p.WaitForExit();

p.Close();
}

private void p_OutputDataReceived(object Sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{

result = e.Data;

}

}

取到的返回值都是空,有木有人用这种方法真正实现过(我主要是想取到最后的那个列表并在窗体里面显示)
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
o0冰凉0o
C# 111,129 成员 642,540 内容