dongzhuang5741 2019-08-18 06:48
浏览 623

在Go中使用Telnet客户端读取数据

I'm trying to read data from some devices via telnet protocol and below is my simple code. I just want to print some meaningful results.

package main

import (
    "fmt"
    "github.com/reiver/go-telnet"

)

func main() {

    conn, _ := telnet.DialTo("10.253.102.41:23")
    fmt.Println(conn)
}

but this is what I got by this way: &{0xc000006028 0xc000004720 0xc000040640}

  • 写回答

1条回答 默认 最新

  • drnl10253 2019-08-18 07:40
    关注

    It's obvious that it gets you &{0xc000006028 0xc000004720 0xc000040640} cause you are printing the connection object and it's the pointer address of that. If you want to print the data, you have to read it through connection using the Read method of the connection. Something like this:

    b := make([]byte, 100)
    n, err := conn.Read(b)
    if err != nil {
        // handle error
    }
    
    fmt.Println(string(b))
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题