27 lines
527 B
Go
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)
|
|
}
|