Skip to content
digineoPublic

About

A simple ping library using ICMP echo requests.

Topics

Resources

Stars

251 stars

Watchers

5 watching

Forks

Repository files navigation

go-ping

GoDoc build Codecov

A simple ICMP Echo implementation, based on golang.org/x/net/icmp.

Some sample programs are provided in cmd/:

  • ping-test is a really simple ping clone
  • multiping provides an interactive TUI to ping multiple hosts
  • ping-monitor pings multiple hosts in parallel, but just prints the summary every so often
  • pingnet allows to ping every host in a CIDR range (e.g. 0.0.0.0/0 :-))

Features

  • IPv4 and IPv6 support
  • Unicast and multicast support
  • Privileged and unprivileged (UDP) support
  • configurable retry amount and timeout duration
  • configurable payload size (and content)
  • round trip time measurement

Usage

For privileged ICMP (requires root or CAP_NET_RAW):

pinger, err := ping.New("0.0.0.0", "::")

For unprivileged ICMP (works on Linux and Darwin if allowed):

pinger, err := ping.NewUDP("0.0.0.0", "::")

On Linux, the process's group must be allowed by net.ipv4.ping_group_range. For example, to allow all groups:

sudo sysctl -w 'net.ipv4.ping_group_range=0 2147483647'

On Linux, unprivileged sockets use their own ICMP identifiers and ignore Pinger.Id. Darwin uses Pinger.Id for both socket types.

On Linux, unprivileged sockets do not receive ICMP errors such as "destination unreachable". An unreachable target results in a timeout instead.

The tests use IPv4 and IPv6 loopback addresses. Set RUN_UNPRIVILEGED=1 to require unprivileged sockets to be available, and RUN_PRIVILEGED=1 to enable the tests that require root or CAP_NET_RAW.

Contribute

Simply fork and create a pull-request. We'll try to respond in a timely fashion.

Software using this library

Please create a pull request to get your software listed.

License

MIT License, Copyright (c) 2018 Digineo GmbH

https://www.digineo.de

About

A simple ping library using ICMP echo requests.

Topics

Resources

Stars

251 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages