dongou6632 2018-05-10 07:58
浏览 145

如何正确检查来自telnet服务器的消息?

I am trying to make a telnet client using the go-telnet library. I am able to connect to the server, but I was expecting to receive some data to login in with user and password.

But I don't get any message. What I could do until now is just send a message to the server and the server prints it.

If I connect using a regular telnet client first thing I have to do is to log in with user and password. I want to replicate this using my own client.

I don't see any examples on GitHub on how to send or receive messages so I am a little confused.

Here is my current code:

func main() {

    err = telnet.DialToAndCall("192.168.206.226:23", caller{})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

type caller struct {}

func (c caller) CallTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader) {
    scanner := bufio.NewScanner(os.Stdin)
    for scanner.Scan() {
        fmt.Println(scanner.Text())
    }
}

Are there any other steps I need to do when connecting? Or am I doing something wrong?

edit (reading part):

//var data []byte
for {
    //numBytes, err := conn.Read(data)
    reader := bufio.NewReader(os.Stdin)
    fmt.Println(reader.ReadString('
'))
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能