Click here to Skip to main content
15,888,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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();
            }
Posted
Updated 25-Oct-15 3:49am
v2

1 solution

Try using NetworkStream[^] instead of StreamReader and StreamWriter

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900