Created
June 6, 2021 22:29
-
-
Save d-Rickyy-b/53e876acbc748277f773d5dd5f30879f to your computer and use it in GitHub Desktop.
Minimal working example for debugging an issue with go-ping/ping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/go-ping/ping" | |
"log" | |
"time" | |
) | |
func execPing(ipAddress string) (bool, error) { | |
pinger, err := ping.NewPinger(ipAddress) | |
if err != nil { | |
return false, err | |
} | |
pinger.SetPrivileged(true) | |
pinger.Count = 3 | |
pinger.Timeout = 5 * time.Second | |
err = pinger.Run() | |
if err != nil { | |
return false, err | |
} | |
return pinger.PacketsRecv >= pinger.Count / 2, nil | |
} | |
func main() { | |
_, err := execPing(<any_unreachable_ip_address>) | |
log.Println(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment