go-ping / ping

ICMP Ping library for Go
MIT License
1.31k stars 344 forks source link

socket: permission denied #191

Closed zengqingfa closed 2 years ago

zengqingfa commented 2 years ago

Mycode is :

func GetNetDelay() (float32, error){
    pinger, err := ping.NewPinger("www.qq.com")
    if err != nil {
        logx.Error(err)
        return 0, err
    }
    pinger.Count = 3
    err = pinger.Run() // Blocks until finished.
    if err != nil {
        logx.Error(err)
        return 0, err
    }

    stats := pinger.Statistics()
    return float32(stats.AvgRtt), nil
}
func Test_GetNetDelay(t *testing.T) {
    rtt, err := GetNetDelay()
    if err != nil{
        logx.Error(err)
    }
    fmt.Println(rtt)
}

The output is :

=== RUN   Test_GetNetDelay
2021/11/29 16:40:22 {"@timestamp":"2021-11-29T16:40:22.360+08","level":"error","content":"network.go:60 socket: permission denied"}
2021/11/29 16:40:22 {"@timestamp":"2021-11-29T16:40:22.360+08","level":"error","content":"network_test.go:20 socket: permission denied"}
0
--- PASS: Test_GetNetDelay (0.01s)
PASS

What should I do?

zengqingfa commented 2 years ago

oh, I find the answer. image

bigOconstant commented 11 months ago

oh, I find the answer. image

screenshot and no link?