Telnet 0.11.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Telnet --version 0.11.1                
NuGet\Install-Package Telnet -Version 0.11.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Telnet" Version="0.11.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Telnet --version 0.11.1                
#r "nuget: Telnet, 0.11.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Telnet as a Cake Addin
#addin nuget:?package=Telnet&version=0.11.1

// Install Telnet as a Cake Tool
#tool nuget:?package=Telnet&version=0.11.1                

Build, Publish, Tag

Telnet

We needed to issue simple commands to (and monitor) a router remotely and that's what we've been able to achieve with this little library. It's usage is simple, it doesn't do anything particularly fancy but if all you're wanting to do is interact with a telnet server by issuing commands, parsing text responses and having the opportunity to respond in code accordingly then hopefully having taken the time to wrap this up in a simple NuGet package will make your life easier!

FWIW I'm happy to take merge requests if they meet incumbent standards, don't break anything and accomodate the code file sharing so all versions work (and likely receive the same change). I'm no TCPIP/Telnet expert but if I can help out with bugs or feature requests I'll do what I can, outside my day job ofc!

v0.9 introduced a significant bump to Net versions and some potentially breaking code changes. Changes to your consuming code should be minimal, but be prepared to test thoroughly. Please raise an Issue if you encounter any problems; in part it'll help others with the same problems and we'll see what we can do to accomodate your use cases.

Usage:

    //Sync Example
    namespace PrimS.Telnet.CiTests
    {
      using FluentAssertions;
      using Xunit;
      using System;
      using System.Text.RegularExpressions;

      [TestClass]
      public class ReadMeExampleFixture
      {
        public const string Pattern =
          "(?:WAN2 total TX: )([0-9.]*) " +
          "((?:[KMG]B)|(?:Bytes))" +
          "(?:[, ]*RX: )([0-9.]*) " +
          "((?:[KMG]B)|(?:Bytes))";
        private const int TimeoutMs = 5000;

        [Fact]
        public void ReadMeExample()
        {
          using (var server = new DummyTelnetServer())
          {
            using (var client = new Client(
              server.IPAddress.ToString(),
              server.Port,
              new CancellationToken()))
            {
              client.IsConnected.Should().Be(true);
              Client.IsWriteConsole = false;
              client.TryLogin(
                "username",
                "password",
                TimeoutMs).Should().Be(true);
              client.WriteLine("show statistic wan2");
              string s = client.TerminatedRead(
                ">",
                TimeSpan.FromMilliseconds(TimeoutMs));
              s.Should().Contain(">");
              s.Should().Contain("WAN2");
              var regEx = new Regex(Pattern);
              regEx.IsMatch(s).Should().Be(true);
              MatchCollection matches = regEx.Matches(s);
              matches.Count.Should().Be(1);
              matches[0].Captures.Count.Should().Be(1);
              matches[0].Groups.Count.Should().Be(5);
              matches[0].Groups[0].Value.Should().Be(
                "WAN2 total TX: 6.3 GB ,RX: 6.9 GB");
              matches[0].Groups[1].Value.Should().Be("6.3");
              matches[0].Groups[2].Value.Should().Be("GB");
              matches[0].Groups[3].Value.Should().Be("6.9");
              matches[0].Groups[4].Value.Should().Be("GB");
            }
          }
        }
      }
    }
    // Async Example
    namespace PrimS.Telnet.CiTests
    {
      using System;
      using FluentAssertions;
      using System.Threading;
      using System.Threading.Tasks;
      using System.Text.RegularExpressions;
      using Xunit;

      public class ReadMeExampleFixture
      {
        public const string Pattern =
          "(?:WAN2 total TX: )([0-9.]*) " +
          "((?:[KMG]B)|(?:Bytes))" +
          "(?:[, ]*RX: )([0-9.]*) " +
          "((?:[KMG]B)|(?:Bytes))";
        private const int TimeoutMs = 5000;

        [Fact]
        public async Task ReadMeExample()
        {
          using (var server = new DummyTelnetServer())
          {
            using (var client = new Client(
              server.IPAddress.ToString(),
              server.Port,
              new CancellationToken()))
            {
              client.IsConnected.Should().Be(true);
              Client.IsWriteConsole = false;
              (await client.TryLoginAsync(
                "username",
                "password",
                TimeoutMs)).Should().Be(true);
              await client.WriteLineAsync("show statistic wan2");
              string s = await client.TerminatedReadAsync(
                ">",
                TimeSpan.FromMilliseconds(TimeoutMs));
              s.Should().Contain(">");
              s.Should().Contain("WAN2");
              var regEx = new Regex(Pattern);
              regEx.IsMatch(s).Should().Be(true);
              MatchCollection matches = regEx.Matches(s);
              matches.Count.Should().Be(1);
              matches[0].Captures.Count.Should().Be(1);
              matches[0].Groups.Count.Should().Be(5);
              matches[0].Groups[0].Value.Should().Be(
                "WAN2 total TX: 6.3 GB ,RX: 6.9 GB");
              matches[0].Groups[1].Value.Should().Be("6.3");
              matches[0].Groups[2].Value.Should().Be("GB");
              matches[0].Groups[3].Value.Should().Be("6.9");
              matches[0].Groups[4].Value.Should().Be("GB");
            }
          }
        }
      }
    }
    // VB.NET Example
    Private Async Function RunRemoteScript(
      commandLine As String) As Task(Of Boolean)
        Using telnet = New Client(
          "HostName",
          23,
          _cancellationSource.Token)
            If Not telnet.IsConnected Then Return False
            Dim loggedOn = Await telnet.TryLoginAsync(
              "username",
              "password",
              SocketTimeout, "#"))
            If Not loggedOn Then Return False
            Await telnet.WriteLine(commandLine)
            Dim serverResponse = Await telnet.TerminatedReadAsync(
              "#",
              TimeSpan.FromMilliseconds(SocketTimeout))
            Debug.Print(serverResponse)
            Await telnet.WriteLine("exit")
            Dim logoutMessage = Await telnet.ReadAsync(
              New TimeSpan(100))
            Debug.Print(logoutMessage)
        End Using
        Return True  ' If we got this far; celebrate
    End Function
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Telnet:

Package Downloads
TeamSpeak3.Metrics

Collect metrics from your TeamSpeak 3 Server

Rosystec.Scan.Lib

sensor aggregator

LgTvControl

This library allows you to remote control your lg tv via their websocket and telnet api

DreamNucleus.Heos

A .Net HEOS CLI client using Reactive Extensions

Simple.K.Socket

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Telnet:

Repository Stars
Kudayasu/Artifice
Xbox One Developer Mode Privilege Escalation
Version Downloads Last updated
0.13.1 2,518 11/20/2024
0.13.0 18,183 7/8/2024
0.12.0 9,751 4/17/2024
0.11.3 170,384 9/17/2022
0.11.2 4,061 9/3/2022
0.11.1 1,745 9/2/2022
0.11.0 1,799 9/2/2022
0.10.2 3,151 8/22/2022
0.10.1 1,769 8/21/2022
0.10.0 1,455 8/20/2022
0.9.1 4,851 8/18/2022
0.9.0-beta0001 8,323 5/16/2018
0.8.6 271,147 9/3/2020
0.8.6-beta0001 413 9/2/2020
0.8.4 51,684 10/9/2019
0.8.3 25,430 3/7/2019
0.8.2 3,421 1/30/2019
0.8.1 136,476 5/8/2018
0.8.0 30,432 3/12/2017
0.7.0 10,843 9/6/2016
0.6.1 53,347 2/25/2016
0.6.0 1,580 1/27/2016
0.5.0 1,588 12/8/2015
0.4.0 3,895 10/27/2015
0.3.2 1,541 9/15/2015
0.3.1 2,473 6/20/2015
0.2.5 82,201 12/15/2014
0.2.0 1,334 11/27/2014
0.1.0 1,632 11/26/2014

Minor signature changes highlighting the Rfc854 fixes dedicated overloads.

     https://github.com/9swampy/Telnet/issues/69
     V0.10 releases unintentionally introduced an external dependency on
     Microsoft.VisualStudio.Threading (Net 4.7.2, 4.8, 6) and System.Memory (4.7.2).
     https://github.com/Wumpf/IncludeToolbox/issues/73 - essentially same problem was observed here.
     [Known issue with MS](https://developercommunity.visualstudio.com/t/joinabletaskfactoryswitchtomainthreadasync-when-bu/662084) - appears to be a known issue that MS closed as low priority

     Release 0.11.0 was a kneejerk fix explicitly adding the unintended dependencies.

     Looking in to it further... release 0.11.1 reverts back to
     [Point 2 - Warning not applicable to .NET Core](https://stackoverflow.com/questions/70964917/optimising-an-asynchronous-call-in-a-constructor-using-joinabletaskfactory-run) instead of accepting the [VSTHRD102 warning](https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD102.md)
     and accordingly drops the dependencies again.