util-go/net/ping/ping_darwin.go

24 lines
482 B
Go
Raw Permalink Normal View History

2018-09-17 11:05:12 +00:00
package ping
2018-09-17 11:07:36 +00:00
import (
"fmt"
"os/exec"
)
2018-09-17 12:46:30 +00:00
func Ping(destination string, option Option) (Result, error) {
2018-09-17 12:45:26 +00:00
option.Validate()
2018-09-17 11:07:36 +00:00
params := make([]string, 0)
params = append(params, destination)
2018-09-20 05:12:13 +00:00
params = append(params, fmt.Sprintf("-c %d", option.GetCount()))
2018-09-17 15:09:04 +00:00
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
2018-09-17 11:07:36 +00:00
pCmd := exec.Command("ping", params...)
output, err := pCmd.CombinedOutput()
if err != nil {
return nil, err
}
return parseDarwinPing(output)
}