util-go/net/ping/ping_linux.go

25 lines
551 B
Go
Raw Normal View History

2018-09-17 11:05:12 +00:00
package ping
import (
"fmt"
"os/exec"
)
func Ping(destination string, options *PingOptions) (*PingResult, error) {
options.Validate()
params := make([]string, 0)
params = append(params, destination)
params = append(params, fmt.Sprintf("-c %d", options.Retry))
params = append(params, fmt.Sprintf("-i %d", options.Interval))
params = append(params, fmt.Sprintf("-w %d", options.Deadline))
pCmd := exec.Command("ping", params...)
output, err := pCmd.CombinedOutput()
if err != nil {
return nil, err
}
return parseLinuxPing(output)
}