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

o0冰凉0o 2013-10-29 10:06:23
命令列表:

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;

}

}

取到的返回值都是空,有木有人用这种方法真正实现过(我主要是想取到最后的那个列表并在窗体里面显示)
...全文
332 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
o0冰凉0o 2013-11-05
  • 打赏
  • 举报
回复
最后用socket写的,主要搞清楚telnet 协议
o0冰凉0o 2013-10-29
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
\r全部换成\n
那部分没错误,已测试
threenewbee 2013-10-29
  • 打赏
  • 举报
回复
\r全部换成\n

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧