util-go/net/ping/ping_linux.go
crusader 7f63063557 ing
2018-09-18 00:09:04 +09:00

27 lines
527 B
Go

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