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 081d8b1256 Update README 1 year ago
cmd/ping Rewrite included ping command 1 year ago
.gitignore uncommit ping binary 4 years ago
.travis.yml Add Travis CI configuration 1 year ago
LICENSE Initial commit 4 years ago
README.md Update README 1 year ago
packet.go Change timestamp handling to support a size of 0 1 year ago
ping.go Initialize statistics by default 1 year ago
ping_test.go Update and cleanup tests 1 year ago
statistics.go Fix calculation of statistics 1 year ago
statistics_test.go Update and cleanup tests 1 year ago
util.go Change timestamp handling to support a size of 0 1 year ago

README.md

ping

GoDoc

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

Installation

Download & install using:

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

Usage

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 {
        panic(err)
}
pinger.PacketLimit = 3
err = pinger.Run()
if err != nil {
	panic(err)
}
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,
}

Note

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.