ICMP Ping library for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Silke 2778508ed9 Fix possible race condition 3 months ago
cmd/ping Rewrite included ping command 3 years ago
.gitignore uncommit ping binary 6 years ago
.travis.yml Add Travis CI configuration 3 years ago
LICENSE Initial commit 6 years ago
README.md Update README 3 years ago
packet.go Expose ping source everywhere 1 year ago
ping.go Fix possible race condition 3 months ago
ping_test.go Update and cleanup tests 3 years ago
statistics.go Expose ping source everywhere 1 year ago
statistics_test.go Update and cleanup tests 3 years ago
util.go Change timestamp handling to support a size of 0 3 years ago




A simple ping library that aims to make the retrieval of ping-statistics easy and manageable. This project is a fork of go-ping, with the following major changes:

  • Unprivileged (UDP) pinging has been removed.
  • Almost all fields have been renamed.
  • Statistics are calculated on the fly, and no history of round-trip times is stored.
  • Main initialisation is not done in the NewPinger function, but when Run is called.
  • The given Size is respected: when the timestamp cannot be stored in the packet, it is kept in the Pinger. The data is also not encoded as JSON.

Also see the documentation


Download & install using:

go get git.slxh.eu/prometheus/ping/...


An full implementation matching the Unix ping command is included in cmd/ping.

The following example sends three packets to Google:

pinger, err := ping.NewPinger("www.google.com")
if err != nil {
pinger.PacketLimit = 3
err = pinger.Run()
if err != nil {
stats := pinger.Statistics

If the destination address is already available, the Pinger can also be initialised directly:

pinger := &ping.Pinger{
    IPAddr:    ipAddr, // some *net.IPAddr
    Host:      ipAddr.String(),
    Size:      ping.DefaultSize,


On Linux, any binary using this code requires the cap_net_raw capability, this can be set on a binary with the following command:

setcap cap_net_raw=+ep $GOPATH/bin/ping

See the documentation for golang.org/x/net/icmp for more details.