C#Telnet到Cisco路由器 [英] C# Telnet to Cisco routers

查看:109
本文介绍了C#Telnet到Cisco路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过telnet连接到Cisco路由器,但我不需要登录才能获得横幅(banner =在进入用户名和密码输入之前路由器提供的信息))



I am trying to connect to a Cisco router via telnet but i don't need to log in only to get the banner (banner = information the router presents before you get into username & password input))

Banner Example:

*
Welcome To 101044555@xxxxxxx *
----------------------------- *
*
ADSL Line : xxxxx 5M *
*
Warning: *
Any unauthorized access to *
this system is unlawful, and *
may be subject to civil and/or *
criminal penalties! *
*
\ CONFIGURED BY-AY *
(o> *
//\ *
V/_ *
|| *
|| *
*



我只需要@之前的数字



问题我可以得到任何输出。我猜这是因为会话没有自然结束




I need only the number before the "@"

The problem I can get any output at all. I am guessing it is because the session does not end naturally

namespace TelNetTesting
{ 
    class Program
    {
        static void Main(string[] args) 
        {
            Console.WriteLine("Please enter the name of a server:"); 
            string server = Console.ReadLine(); 
            TcpClient client = new TcpClient(server, 23); 
            StreamReader sr = new StreamReader(client.GetStream()); 
            StreamWriter sw = new StreamWriter(client.GetStream());
            
            try
            {
                sw.WriteLine("exit");
                sw.Flush();
    
                string data = sr.ReadLine();
                while (data != null)
                {
                    Console.WriteLine(data);
                    data = sr.ReadLine();
                }
                client.Close();
            }

推荐答案

尝试使用 NetworkStream [ ^ ]而不是StreamReader和StreamWriter



看一下这个例子。

TcpClient.GetStream方法 [ ^ ]
Try using NetworkStream[^] instead of StreamReader and StreamWriter

Have a look at this example.
TcpClient.GetStream Method[^]


这篇关于C#Telnet到Cisco路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆