RFC 854/855 compliant Telnet protocol implementation for .NET.
dotnet add package NIS.Protocols.Telnet --version 1.0.0
using NIS.Protocols.Telnet; var client = new TelnetClient(); client.DataReceived += (sender, e) => Console.WriteLine(Encoding.ASCII.GetString(e.Data)); client.CommandReceived += (sender, e) => Console.WriteLine($"Command: {e.Command}"); await client.ConnectAsync("192.168.1.1", 23); await client.SendLineAsync("username"); await client.SendLineAsync("password");
- RFC 854: Telnet Protocol Specification (IAC escape, commands, subnegotiation)
- RFC 855: Telnet Option Specification (subnegotiation format, IAC inside params)
RFC documents are included in the docs/ directory of this repository.
To install from a private BaGetter feed:
# Add the BaGetter source dotnet nuget add source https://your-bagetter-url/v3/index.json --name BaGetter # Install the package dotnet add package NIS.Protocols.Telnet --version 1.0.0 --source BaGetter
Or add to your NuGet.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="BaGetter" value="https://your-bagetter-url/v3/index.json" /> </packageSources> </configuration>
The public API surface is intentionally minimal:
TelnetClient- Main consumer APIConnectAsync(string host, int port)- Connect to a Telnet serverDisconnectAsync()- Disconnect from the serverSendAsync(ReadOnlyMemory<byte> data)- Send raw bytes (IAC escaped automatically)SendLineAsync(string text)- Send text with CRLF appendedReadUntilAsync(string expected, TimeSpan timeout)- Read until a string is foundReadLineAsync(TimeSpan timeout)- Read a single line- Events:
DataReceived,CommandReceived,RawBytesReceived
TelnetCommand- Enum of Telnet commands (IAC, WILL, WONT, DO, DONT, SB, SE, etc.)TelnetDataEventArgs- Event args for data received (byte[] Data)TelnetCommandEventArgs- Event args for commands received (TelnetCommand Command,byte? Option,byte[]? SubnegotiationData)
Implementation classes (TelnetStreamParser, OptionNegotiator, NvtDataProcessor) are internal to allow future refactoring without breaking changes.
GPL v3 - see LICENSE