2018-09-17 11:05:12 +00:00
|
|
|
package ping
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2018-09-17 12:45:26 +00:00
|
|
|
func Ping(destination string, option Option) (Result, error) {
|
|
|
|
option.Validate()
|
2018-09-17 11:05:12 +00:00
|
|
|
|
|
|
|
params := make([]string, 0)
|
2018-09-17 11:13:01 +00:00
|
|
|
params = append(params, "/C")
|
2018-09-17 12:45:26 +00:00
|
|
|
params = append(params, fmt.Sprintf("chcp 437 && ping %s -n %d -w %d", destination, option.Retry(), option.Deadline()*1000))
|
2018-09-17 11:05:12 +00:00
|
|
|
|
2018-09-17 11:13:01 +00:00
|
|
|
pCmd := exec.Command("cmd.exe", params...)
|
2018-09-17 11:05:12 +00:00
|
|
|
output, err := pCmd.CombinedOutput()
|
|
|
|
if err != nil {
|
2018-09-17 11:13:17 +00:00
|
|
|
return nil, err
|
2018-09-17 11:05:12 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 11:10:57 +00:00
|
|
|
return parseWindowsPing(output)
|
2018-09-17 11:05:12 +00:00
|
|
|
}
|