telnetClient

package module
v0.0.0-...-2da299d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2022 License: MIT Imports: 3 Imported by: 0

README

telnetClient

a even easier telnet client for command servers using a resp format like:

  • error: err, <errormsg>
  • success: OK, <resp>[, <otherval>]...

pkg.go.dev

Connect to server:
c, err := telnetClient.NewController("<destination>")
if err != nil {
	fmt.Println(err)
}
Send a command
resp, err := c.Exec("<command>")
if err != nil {
	fmt.Println(err)
}

fmt.Println(resp)
End connection
err := c.Close()
if err != nil {
	fmt.Println(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseResponse

func ParseResponse(res string) ([]string, error)

parses string response

Types

type Controller

type Controller struct {
	Conn           *telnet.Conn
	ResponseStream chan string
}

The Controller struct

func NewController

func NewController(dest string) (*Controller, error)

creates a new controller

func NewReciveController

func NewReciveController(dest, selftype string) (*Controller, error)

Create a new controller that automatically revices and dumps content to the ResponseStream channel in Controller selftype is the first thing send my client to identify

func (*Controller) Close

func (c *Controller) Close() error

closes the connection

func (*Controller) Exec

func (c *Controller) Exec(cmd string) ([]string, error)

writes cmd and returns when reciving response

func (*Controller) ReadToChannel

func (c *Controller) ReadToChannel(b byte)

reads until b, then sends response to ResponseStream channel

func (*Controller) ReadUntil

func (c *Controller) ReadUntil(b byte) ([]byte, error)

reads until b is encounterd

func (*Controller) Write

func (c *Controller) Write(cmd string) error

writes string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL