Documentation ¶
Overview ¶
Package telnet implements the telnet protocol.
Index ¶
- Constants
- Variables
- func IsNotSupported(err error) bool
- func Prompt(term Terminal, format string) string
- type Client
- type Conn
- type Console
- func (c *Console) FQDN() string
- func (c *Console) Hostname() string
- func (c *Console) Info() *terminfo.Terminfo
- func (c *Console) Prompt() error
- func (c *Console) Read(p []byte) (n int, err error)
- func (c *Console) SetSize(_, _ int) error
- func (c *Console) SetSpeed(_, _ int) error
- func (c *Console) SetType(_ string) error
- func (c *Console) SetXDisplayLocation(_ string) error
- func (c *Console) Size() (int, int)
- func (c *Console) Speed() (int, int)
- func (c *Console) Type() string
- func (c *Console) Write(p []byte) (n int, err error)
- func (c *Console) XDisplayLocation() string
- type Protocol
- func (p *Protocol) Conn() net.Conn
- func (p *Protocol) Feed(buf []byte) error
- func (p *Protocol) Negotiate(timeout time.Duration) (err error)
- func (p *Protocol) Next() event.Event
- func (p *Protocol) Option(opt byte) bool
- func (p *Protocol) Read(b []byte) (int, error)
- func (p *Protocol) ReadByte() (byte, error)
- func (p *Protocol) RemoteOption(opt byte) bool
- func (p *Protocol) SetOption(opt byte, enabled bool)
- func (p *Protocol) SubnegotiateMSSP(b []byte) error
- func (p *Protocol) Write(b []byte) (int, error)
- func (p *Protocol) WriteOOB(b []byte) (int, error)
- func (p *Protocol) WriteRaw(b []byte) (int, error)
- type ProtocolState
- type Server
- type ServerTerminal
- func (s ServerTerminal) Charset() string
- func (s ServerTerminal) Environment() map[string]string
- func (s ServerTerminal) Info() *terminfo.Terminfo
- func (s ServerTerminal) Name() string
- func (s *ServerTerminal) Prompt() error
- func (s ServerTerminal) Read(p []byte) (int, error)
- func (s *ServerTerminal) SetCharset(charsets []string) error
- func (s *ServerTerminal) SetEnvironment(env map[string]string) error
- func (s *ServerTerminal) SetName(name string)
- func (s *ServerTerminal) SetPrompt(prompt string)
- func (s ServerTerminal) SetSize(w, h int) error
- func (s *ServerTerminal) SetSpeed(rx, tx int) error
- func (s *ServerTerminal) SetVersion(version string)
- func (s *ServerTerminal) Size() (int, int)
- func (s ServerTerminal) Speed() (int, int)
- func (s ServerTerminal) Version() string
- func (s ServerTerminal) Write(p []byte) (int, error)
- type Stream
- type Terminal
- type TerminalWithCharset
- type TerminalWithEnvironment
- type TerminalWithHostname
- type TerminalWithLocation
- type TerminalWithLogout
- type TerminalWithReturnCode
- type TerminalWithSize
- type TerminalWithSpeed
- type TerminalWithType
- type TerminalWithUsername
- type TerminalWithVersion
- type TerminalWithXDisplayLocation
Constants ¶
const ( BINARY byte = iota // 8-bit data path ECHO // Echo RCP // Prepare to reconnect SGA // Suppress Go Ahead NAMS // Approximate Message Size STATUS // Status TM // Timing Mark RCTE // Remote Controlled Transmission and Echo NAOL // Negotiate About Output Line (width) NAOP // Negotiate About Output Page (size) NAOCRD // Negotiate About CR Disposition NAOHTS // Negotiate About Horizontal Tabstops NAOHTD // Negotiate About Horizontal Tab Disposition NAOFFD // Negotiate About Formfeed Disposition NAOVTS // Negotiate About Vertical Tabstops NAOVTD // Negotiate About Vertial Tab Disposition NAOLFD // Negotiate About Output LF Disposition XASCII // Extended ASCII character set LOGOUT // Force logout BM // Byte Macro DET // Data Entry Terminal SUPDUP // Supdup protocol SUPDUPOUTPUT // Supdup output SNDLOC // Send Location TTYPE // Terminal Type EOR // End Of Record TUID // TACAS User Identification VT3270REGIME // vt3270 regime X3PAD // X.3 Pad NAWS // Window Size TSPEED // Terminal Speed LFLOW // Remote Flow Control LINEMODE // Linemode option XDISPLOC // X Display Location ENVIRON // Environment Variables AUTHENTICATION // Authenticate ENCRYPT // Encrypt NEW_ENVIRON // Environment Variables (new) TN3270E // TN3270E XAUTH // XAuth CHARSET // Character set RSP // Remote Serial Port COM_PORT_OPTION // COM Port Control Option SUPPRESS_LOCAL_ECHO // Telnet Suppress Local Echo TLS // Telnet StartTLS KERMIT // Kermit SEND_URL // Send URL FORWARD_X // Forward X MSDP byte = 69 MSSP byte = 70 COMPRESS byte = 85 COMPRESS2 byte = 86 MSP byte = 90 MXP byte = 91 MSP2 byte = 92 ZMP byte = 93 )
Telnet protocol options (arpa/telnet.h)
const ( PRAGMA_LOGON byte = iota + 138 // Telopt Pragma Logon SSPI_LOGON // Telopt SSPI Logon PRAGMA_HEARTBEAT // Telopt Pragma Heartbeat )
const ( EOF byte = iota + 236 // End Of File SUSP // Suspend ABORT // Abort CMD_EOR // End Of Record SE // Sub-negotiation End NOP // No-Operation DM // Data Mark BRK // Break IP // Interrupt Process AO // Abort Output AYT // Are You There? EC // Erase Character EL // Erase Line GA // Go Ahead SB // Sub-negotiation Begin WILL // Will WONT // Wont DO // Do DONT // Dont IAC // Interpret as Command )
TTYPE bytes
const ( MTTS_ANSI byte = 1 << iota MTTS_VT100 MTTS_UTF8 MTTS_256_COLORS MTTS_MOUSE_TRACKING MTTS_OSC_COLOR_PALETTE MTTS_SCREEN_READER MTTS_PROXY )
MTTS bytes
MSSP bytes
const ( MSDP_VAR byte = 1 + iota MSDP_VAL MSDP_TABLE_OPEN MSDP_TABLE_CLOSE MSDP_ARRAY_OPEN MSDP_ARRAY_CLOSE )
MSDP values
Environment commands (rfc1572)
Environment values (rfc1572)
const ( REQUEST byte = 1 + iota ACCEPTED REJECTED TTABLE_IS TTABLE_REJECTED TTABLE_ACK TTABLE_NAK )
Charset commands ()
const NULL byte = 0
NULL is the NULL byte.
Variables ¶
var ( // DefaultServerOption is a map of telnet options negotiated by a default server. DefaultServerOption = map[byte]bool{ SGA: true, TSPEED: true, TTYPE: true, NAWS: true, NEW_ENVIRON: true, } DefaultNegotiationTimeout = time.Second * 10 )
var ( ErrTimeout = errors.New("telnet: timeout") ErrNotConnected = errors.New("telnet: not connected") ErrNotSupported = notSupported(true) )
Common errors
var ( // DefaultEnvironmentRequest are the default environment variable being requested. DefaultEnvironmentRequest = []string{ "USER", "HOSTNAME", "UID", "TERM", "COLUMNS", "LINES", "DISPLAY", "LANG", "SYSTEMTYPE", "ACCT", "JOB", "PRINTER", "SFUTLNTVER", "SFUTLNTMODE", "LC_ALL", "VISUAL", "EDITOR", "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", } )
Functions ¶
func IsNotSupported ¶
IsNotSupported checks if the error is a not-supported error.
func Prompt ¶
Prompt resolves a prompt with format.
'%%' A single '%'. '%#' Prompt character. '%u' Username. '%h' Hostname. '%H' Full hostname. '%i' Terminal type. '%?' Return code last command processed. '%E' Encoding of session. '%s' Name of shell. '%v' Version of shell. '%t' Time of day in 12-hour AM/PM format. '%T' Time of day in 24-hour format. '%p' Time of day in 12-hour format with seconds, AM/PM format. '%P' Time of day in 24-hour format with seconds. '%d The weekday in `Day' format. '%D' The day in `dd' format. '%w' The month in `Mon' format. '%W' The month in `mm' format. '%y' The year in `yy' format. '%Y' The year in `yyyy' format. '%z' The timezone in `[-+]NNNN' format. '%Z' The timezone name in `TZNAME' format. '%-' Reset formatting. '%b' Bold formatting. '%0'..'%7' Foreground color.
Types ¶
type Client ¶
type Client struct { net.Conn // TermFunc allocates a new terminal for the incoming connection. If left // empty a new Virtual terminal will be created. TermFunc func(Stream) Terminal // StreamFunc allocates a new stream for the incoming connection. If left // empty a new telnet Protocol stream. StreamFunc func(Conn) Stream }
Client implements a telnet client.
func Dial ¶
Dial opens a new telnet client connection. Output is sent to standard output and input is read from standard input.
func (*Client) Dial ¶
Dial starts connecting over the network.
type Conn ¶
type Conn interface { // Conn is the (raw) network connection. net.Conn // IsClient indicates that the connection is a client connection. IsClient() bool // IsServer indicates that the connection is a server connection. IsServer() bool // Terminal is the connected terminal. Terminal() Terminal }
Conn is a telnet connection.
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console implements the Terminal interface using standard output.
func NewConsole ¶
NewConsole creates a new Terminal tied to a local file descriptor, such as os.Stdout.
func (*Console) SetXDisplayLocation ¶
SetXDisplayLocation is not supported.
func (*Console) Size ¶
Size returns the current terminal size. If the operation is not supported by the operating system, it will default to 80x24.
func (*Console) Speed ¶
Speed returns the receive and transmit baudrates of the current output device.
type Protocol ¶
type Protocol struct { // Events Events chan event.Event // IsServer interprets telnet commands in server or client mode. IsServer bool // contains filtered or unexported fields }
Protocol implements the telnet protocol and Stream interface.
func NewProtocol ¶
NewProtocol starts a new telnet stream on the connection.
func (*Protocol) Feed ¶
Feed interprets bytes from remote.
func (*Protocol) Negotiate ¶
Negotiate telnet options
func (*Protocol) Read ¶
Read reads bytes from the internal buffer, it will block if no data is available.
func (*Protocol) ReadByte ¶
ReadByte reads one byte from the internal buffer, it will block if no data is available.
func (*Protocol) RemoteOption ¶
RemoteOption returns the remote status.
func (*Protocol) SetOption ¶
SetOption sets the local status.
func (*Protocol) SubnegotiateMSSP ¶
SubnegotiateMSSP parses a MUD Server Status Protocol sub-negotiation
func (*Protocol) Write ¶
Write transmits in-band data.
func (*Protocol) WriteOOB ¶
WriteOOB transmits out-of-band data.
type ProtocolState ¶
type ProtocolState uint8
ProtocolState is the current state of the telnet state machine.
func (ProtocolState) String ¶
func (s ProtocolState) String() string
type Server ¶
type Server struct { // Server listen address. Addr string // Banner message which gets sent on-connect. Some formatting strings are // allowed, resolved via the Prompt function. Banner string // Debug messages. Debug bool // Option is a map of telnet protocol options negotiated with new clients. Option map[byte]bool // TermFunc allocates a new terminal for the incoming connection. If left // empty a new Virtual terminal will be created. TermFunc func(Stream) Terminal // StreamFunc allocates a new stream for the incoming connection. If left // empty a new telnet Protocol stream. StreamFunc func(Conn) Stream // NegotiationTimeout is the time we allow for the client and server to // negotiate telnet options. NegotiationTimeout time.Duration }
type ServerTerminal ¶
type ServerTerminal struct {
// contains filtered or unexported fields
}
ServerTerminal implements the Terminal interface for a Server connection.
func NewServerTerminal ¶
func NewServerTerminal(stream Stream) *ServerTerminal
func (ServerTerminal) Charset ¶
func (s ServerTerminal) Charset() string
func (ServerTerminal) Environment ¶
func (s ServerTerminal) Environment() map[string]string
func (ServerTerminal) Info ¶
func (s ServerTerminal) Info() *terminfo.Terminfo
func (ServerTerminal) Name ¶
func (s ServerTerminal) Name() string
func (*ServerTerminal) Prompt ¶
func (s *ServerTerminal) Prompt() error
func (ServerTerminal) Read ¶
func (s ServerTerminal) Read(p []byte) (int, error)
func (*ServerTerminal) SetCharset ¶
func (s *ServerTerminal) SetCharset(charsets []string) error
func (*ServerTerminal) SetEnvironment ¶
func (s *ServerTerminal) SetEnvironment(env map[string]string) error
func (*ServerTerminal) SetName ¶
func (s *ServerTerminal) SetName(name string)
func (*ServerTerminal) SetPrompt ¶
func (s *ServerTerminal) SetPrompt(prompt string)
func (ServerTerminal) SetSize ¶
func (s ServerTerminal) SetSize(w, h int) error
func (*ServerTerminal) SetSpeed ¶
func (s *ServerTerminal) SetSpeed(rx, tx int) error
func (*ServerTerminal) SetVersion ¶
func (s *ServerTerminal) SetVersion(version string)
func (*ServerTerminal) Size ¶
func (s *ServerTerminal) Size() (int, int)
func (ServerTerminal) Speed ¶
func (s ServerTerminal) Speed() (int, int)
func (ServerTerminal) Version ¶
func (s ServerTerminal) Version() string
func (ServerTerminal) Write ¶
func (s ServerTerminal) Write(p []byte) (int, error)
type Stream ¶
type Stream interface { // Reader implements reading data bytes from the stream. io.Reader io.ByteReader // Writer implements writing to the stream. io.Writer // WriteRaw writes unescaped bytes. WriteRaw([]byte) (int, error) // WriteOOB writes out-of-band bytes. WriteOOB([]byte) (int, error) // Feed raw bytes. Feed([]byte) error // Option gets a telopt status for local. Option(byte) bool // SetOption sets a telopt status for local. SetOption(byte, bool) // RemoteOption gets a telopt status for remote. RemoteOption(byte) bool // Negotiate telnet options. Negotiate(time.Duration) error // Next event sent by remote. Next() event.Event // Conn is the underlying system transport. Conn() net.Conn }
Stream handles raw bytes
type Terminal ¶
type Terminal interface { // Writer implements writing to the terminal. io.Writer // Reader implements reading from the connected stream. io.Reader // Info returns the terminfo entry (can be nil). Info() *terminfo.Terminfo // Prompt starts interacting with remote end. Prompt() error }
Terminal implements a Reader/Writer.
type TerminalWithCharset ¶
TerminalWithCharset implements a terminal with charset support (rfc2066)
type TerminalWithEnvironment ¶
type TerminalWithEnvironment interface { Environment() map[string]string SetEnvironment(map[string]string) error }
TerminalWithEnvironment implements a termina with environment support
type TerminalWithHostname ¶
TerminalWithHostname implements a terminal with hostname and FQDN.
type TerminalWithLocation ¶
TerminalWithLocation implements a terminal with send-location support (rfc779)
type TerminalWithLogout ¶
type TerminalWithLogout interface {
Logout()
}
TerminalWithLogout implements a terminal with logout support
type TerminalWithReturnCode ¶
type TerminalWithReturnCode interface {
ReturnCode() int
}
TerminalWithReturnCode implements a terminal with return code.
type TerminalWithSize ¶
TerminalWithSize implements a terminal with window size support (rfc1073)
type TerminalWithSpeed ¶
TerminalWithSpeed implements a terminal with speed support (rfc1079)
type TerminalWithType ¶
TerminalWithType implements a terminal with terminal type support (rfc1091)
type TerminalWithUsername ¶
type TerminalWithUsername interface {
Username() string
}
TerminalWithUsername implements a terminal with username.
type TerminalWithVersion ¶
TerminalWithVersion implements a terminal with name and version.