123456789101112131415161718192021222324252627282930 |
- package networkdiagnostic_test
- import (
- "fmt"
- "github.com/go-ping/ping"
- "runtime"
- "testing"
- "time"
- )
- func TestPing(t *testing.T) {
- pinger, err := ping.NewPinger("console.cengcloud.com")
- if err != nil {
- panic(err)
- }
- os := runtime.GOOS
- pinger.Count = 3
- pinger.Timeout = 5 * time.Second
- pinger.Interval = 1 * time.Second
- if os == "windows" {
- pinger.SetPrivileged(true)
- }
- err = pinger.Run() // Blocks until finished.
- if err != nil {
- panic(err)
- }
- stats := pinger.Statistics() // get send/receive/duplicate/rtt stats
- fmt.Println("", stats)
- fmt.Println("", os)
- }
|