func (pinger *Pinger) PingAttempts(destination *net.IPAddr, timeout time.Duration, attempts int) (rtt time.Duration, err error) {
	if attempts < 1 {
		err = errors.New("zero attempts")
	} else {
		for i := 0; i < attempts; i++ {
			rtt, err = pinger.Ping(destination, timeout)
			if err == nil {
				break  
			}
		}
	}
	return
}
PingAttempts sends ICMP echo requests with a timeout per request, retrying upto `attempt` times .
Will finish early on success and return the round trip time of the last ping.
package ping
import (
	"context"
	"errors"
	"net"
	"sync"
	"sync/atomic"
	"time"
	"golang.org/x/net/icmp"
	"golang.org/x/net/ipv4"
	"golang.org/x/net/ipv6"
)