24 lines
520 B
Go
24 lines
520 B
Go
|
package ping
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
func Ping(destination string, options *PingOptions) (string, error) {
|
||
|
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
|
||
|
}
|
||
|
|
||
|
return parseLinuxPing(output)
|
||
|
}
|