telnet library fork

kayos@tcp.direct bcb5811a5a more comprehensive regex 1 week ago
README.md 4eede7889d Update README.md 2 years ago
cmd.go 867e38478b SetPrompt added 2 years ago
constants.go 3f1e1a8505 strip iac 2 years ago
login.go bcb5811a5a more comprehensive regex 1 week ago
negotiation.go 3f1e1a8505 strip iac 2 years ago
reader.go f30684f28b fix 2 years ago
telnet.go bcb5811a5a more comprehensive regex 1 week ago
telnet_test.go 867e38478b SetPrompt added 2 years ago
writer.go 68a5f1bdf0 first commit 2 years ago

README.md

tclient

Simple telnet client lib, written in golang.

Some docs: https://godoc.org/github.com/ircop/tclient

Example usage:

main.go:

	client := tclient.New(5, "")
	err := client.Open("10.10.10.10", 23)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// you can omit this, or do auth stuff manually by calling `ReadUntil` with login/password prompts
	out, err := client.Login("script2", "pw3")
	if err != nil {
		panic(err)
	}
	fmt.Printf(out)

	out, err = client.Cmd("show time")
	if err != nil {
		panic(err)
	}
	fmt.Printf(out)

Output:

Output

Matching callbacks

You can define regular expressions and callbacks that would be called when current output string will match one of regexps.

For example, we need to catch pagination on D-Link switch. Sample show switch paginated output:

Show switch

There is no prompt, so app will stuck on this. So we need to catch something like CTRL+C ESC q Quit SPACE n Next Page ENTER Next Entry a All and send 'n' (next page) or 'a' (all pages). Like this:

	// matching "CTRL+C ESC q Quit SPACE n Next Page ENTER Next Entry a All"
	err = client.RegisterCallback(`(?msi:CTRL\+C.+?a A[Ll][Ll]\s*)`, func() {
		client.WriteRaw([]byte("a"))
	})
	if err != nil {
		panic(err)
	}

Note we are using WriteRaw(), not Write(), because Write() adds CRLF to given string.

TODO

Implement pagination parsing/manipulating (various network devices paging their output)

Implement parsing regexps with callbacks. For output pagination purposes, etc.