Skip to content
/ telnet Public

Telnet protocol implementation in go (golang)

License

Notifications You must be signed in to change notification settings

plyul/telnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Telnet protocol implementation in GO (golang).

Telnet client example:

package main

import (
	"fmt"
	"github.com/plyul/telnet"
	"golang.org/x/sys/unix"
	"io"
	"os"
)

func main() {
	address := "localhost:2023"
	connection, err := telnet.Connect(address)
	if err != nil {
		fmt.Print(err)
		return
	}
	defer connection.Close()

	fd := int(os.Stdout.Fd())
	w, h, _ := getSize(fd)
	connection.SetWindowSize(w, h)
	
	go io.Copy(connection, os.Stdin)
	_, err = io.Copy(os.Stdout, connection)
}

func getSize(fd int) (width, height int, err error) {
	ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
	if err != nil {
		return -1, -1, err
	}
	return int(ws.Col), int(ws.Row), nil
}

About

Telnet protocol implementation in go (golang)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages