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 9817c0cfbb Improve thread-safety of Pinger 2 years ago
cmd/ping Rewrite included ping command 2 years ago
.gitignore uncommit ping binary 5 years ago
.travis.yml Add Travis CI configuration 2 years ago
LICENSE Initial commit 5 years ago
README.md Update README 2 years ago
packet.go Change timestamp handling to support a size of 0 2 years ago
ping.go Improve thread-safety of Pinger 2 years ago
ping_test.go Update and cleanup tests 2 years ago
statistics.go Make Statistics more thread-safe 2 years ago
statistics_test.go Update and cleanup tests 2 years ago
util.go Change timestamp handling to support a size of 0 2 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.