doumeng9188 2016-02-03 01:24
浏览 254
已采纳

您可以使用icmp定位特定端口吗?

I believe the title is pretty self explanatory, but just in case, I'll explain further.

I am writing a function in Go that uses icmp to check if a particular service is running. I got this idea from ping implemented in Go. When I try command line ping, it can not resolve 127.0.0.1:8080, and the function follows suit, which makes sense. But can I use icmp to check that address and port with something I missing? Or should I just stick something like tcp to target a port?

Right now I have this simple function, and I could just use tcp, but I'm curious if I could use something like icmp.

func (c *Controller) Ping() error {
    conn, connErr := net.Dial("ip4:icmp", c.APIServerIP)
    if connErr != nil {
        return connErr
    }
    conn.SetDeadline(time.Now().Add(3 * time.Second))
    defer conn.Close()
    return nil
}
  • 写回答

1条回答 默认 最新

  • dtjo87679 2016-02-03 01:55
    关注

    No. There are no ports in ICMP.

    If you want to know whether a specific TCP server is running, try to connect to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题