github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/pkg/util/net/util.go (about)

     1  package net
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"os/exec"
     7  )
     8  
     9  // IsReachable returns the destNode is reachable with ping.
    10  func IsReachable(ctx context.Context, destNode string) bool {
    11  	cmd := exec.CommandContext(ctx, "ping", "-w", "1", destNode)
    12  	return cmd.Run() == nil
    13  }
    14  
    15  // HostIP looks up an IP for a hostname.
    16  func HostIP(host string) string {
    17  	ips, err := net.LookupIP(host)
    18  	if err != nil {
    19  		return ""
    20  	}
    21  	return ips[0].String()
    22  }