.NET - a simple telnet client

Install package

Visit github.com

class Program
{
    static async Task TestTelnet()
    {
        const int TimeoutMs = 10000;
        using (Client client = new Client("[ServerIP]", 23, new System.Threading.CancellationToken())) {
            if (client.IsConnected) {
                if (await client.TryLoginAsync("[Username]", "[Password]", TimeoutMs)) {
                    await client.WriteLine("show clock");
                    string s = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs));
                    Console.WriteLine(s.ToUpper());
                    await client.WriteLine("show cca");
                    string s2 = await client.TerminatedReadAsync(">", TimeSpan.FromMilliseconds(TimeoutMs));
                    Console.WriteLine(s2.ToUpper());
                }
            }
        }
    }
 
    static void Main(string[] args)
    {
        Task.Run(async () => {
            await TestTelnet();
        }).Wait();
    }
}

Output

SHOW CLOCK
*23:30:46.299 UTC SUN MAR 25 2018
SERVER>
SHOW CCA
INDEX  LENGTH  FLAGS  NAME
2      12      3      PEER
1      4       1      VPDN
0      148     98     PPP
SERVER>