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 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问题