Open
Description
The following code works fine on Windows, Ubuntu 22.04, MacOS, and some others. But it fails on Debian 12.
I've tried running it as root vs a user with the same result.
I've also tried SetPrivileges and the same result.
How to resolve this?
Thanks
ping -c 1 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=4.19 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 4.190/4.190/4.190/0.000 ms
$ ./testping
socket: permission denied
false
$ sudo ./testping
socket: permission denied
false
$
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$
package main
import (
"fmt"
"runtime"
"time"
probing "github.com/prometheus-community/pro-bing"
)
func main() {
isup := Ping("8.8.8.8")
fmt.Println(isup)
}
func Ping(ip string) bool {
pinger, err := probing.NewPinger(ip)
if err != nil {
return false
}
pinger.Count = 1
pinger.Timeout = 250 * time.Millisecond
if runtime.GOOS == "windows" {
pinger.SetPrivileged(true)
}
err = pinger.Run()
if err != nil {
fmt.Println(err)
return false
}
stats := pinger.Statistics()
return stats.PacketsRecv > 0
}
Metadata
Metadata
Assignees
Labels
No labels