util-go/net/ping/ping_windows.go

24 lines
527 B
Go
Raw Normal View History

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