util-go/net/ping/ping_darwin.go
crusader 53acbc1c03 ing
2018-09-17 21:45:26 +09:00

24 lines
477 B
Go

package ping
import (
"fmt"
"os/exec"
)
func Ping(destination string, options Option) (Result, error) {
option.Validate()
params := make([]string, 0)
params = append(params, destination)
params = append(params, fmt.Sprintf("-c %d", option.Retry()))
params = append(params, fmt.Sprintf("-i %d", option.Interval()))
pCmd := exec.Command("ping", params...)
output, err := pCmd.CombinedOutput()
if err != nil {
return nil, err
}
return parseDarwinPing(output)
}