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

o0冰凉0o 2013-10-29 04:40:44
命令列表:

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;

}

}


取到的返回值都是空,有木有人用这种方法真正实现过(我主要是想取到最后的那个列表并在窗体里面显示)
...全文
333 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
o0冰凉0o 2013-11-05
  • 打赏
  • 举报
回复
最后用socket写的,主要搞清楚telnet 协议
max_min_ 2013-10-29
  • 打赏
  • 举报
回复
取不到值,说明哪里调用失败了!楼主回头查查代码!检查各个接口的返回值! 另外c# 可以去.net大板块下有个c#小板块,那里可能有人更专业的回答!

4,358

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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