multiping

package
v0.6.3-beta01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

This file code is based on https://github.com/go-ping/ping

Index

Constants

View Source
const (
	ProtocolIpv4 = ProtocolVersion(4)
	ProtocolIpv6 = ProtocolVersion(6)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiPing

type MultiPing struct {
	sync.RWMutex

	// Timeout specifies a timeout before ping exits, regardless of how many
	// packets have been received. Default is 1s.
	Timeout time.Duration

	// Tracker: Used to uniquely identify packet when non-priviledged
	Tracker int64
	// contains filtered or unexported fields
}

func New

func New(privileged bool) (*MultiPing, error)

func (*MultiPing) Ping

func (mp *MultiPing) Ping(data *PingData)

Ping is blocking function and runs for mp.Timeout time and pings all hosts in data

type PingClient

type PingClient interface {
	PingProcess(pr *PingData)
}

Unified interface to process ping data

type PingData

type PingData struct {
	// contains filtered or unexported fields
}

Ping data. Holds host information and ping statistics. Use Add, Get and Iterate functions. No internal logic will be exposed.

func NewPingData

func NewPingData() *PingData

func (*PingData) Add

func (pr *PingData) Add(hosts ...netip.Addr)

Add - adds some hosts to be pinged

func (*PingData) Append

func (pr *PingData) Append(data *PingData)

Append - merges 2 PingData into one

func (*PingData) Count

func (pr *PingData) Count() int

Returns count of configured host

func (*PingData) Del

func (pr *PingData) Del(hosts ...netip.Addr)

Del removes some hosts from ping list

func (*PingData) Dump

func (pr *PingData) Dump(w io.Writer, title ...string)

func (*PingData) Flush

func (pr *PingData) Flush()

Flush removes all configured hosts

func (*PingData) Get

func (pr *PingData) Get(ip netip.Addr) (PingStats, bool)

Get searches for ping statistics of a host

func (*PingData) Iterate

func (pr *PingData) Iterate(callback func(ip netip.Addr, val PingStats))

Iterate runs through all hosts and calls callback for stats processing

func (*PingData) Reset

func (pr *PingData) Reset()

Reset statistics. Host list remains unchainged.

type PingStats

type PingStats struct {
	// contains filtered or unexported fields
}

A single host ping statistics

func (*PingStats) Latency

func (s *PingStats) Latency() float32

Latency returns average latency in miliseconds

func (*PingStats) Loss

func (s *PingStats) Loss() float32

Loss returns calculated ping loss

func (*PingStats) Reset

func (s *PingStats) Reset()

Reset statistics to zero values

func (*PingStats) Rtt

func (s *PingStats) Rtt() time.Duration

Rtt returns last packet rtt

func (*PingStats) String

func (s *PingStats) String() string

func (*PingStats) Valid

func (s *PingStats) Valid() bool

type Pinger

type Pinger struct {
	// Size of packet being sent
	Size int

	// Tracker: Used to uniquely identify packet when non-priviledged
	Tracker int64
	// contains filtered or unexported fields
}

Pinger represents a packet sender.

func NewPinger

func NewPinger(network, protocol string, id uint16) *Pinger

NewPinger returns a new Pinger instance

func (*Pinger) Addr

func (p *Pinger) Addr() string

Addr returns the string ip address of the target host.

func (*Pinger) IPAddr

func (p *Pinger) IPAddr() *netip.Addr

IPAddr returns the ip address of the target host.

func (*Pinger) Privileged

func (p *Pinger) Privileged() bool

Privileged returns whether pinger is running in privileged mode.

func (*Pinger) SendICMP

func (p *Pinger) SendICMP(sequence uint16) error

func (*Pinger) SetIPAddr

func (p *Pinger) SetIPAddr(ipaddr *netip.Addr)

SetIPAddr sets the ip address of the target host.

func (*Pinger) SetPrivileged

func (p *Pinger) SetPrivileged(privileged bool)

SetPrivileged sets the type of ping pinger will send. false means pinger will send an "unprivileged" UDP ping. true means pinger will send a "privileged" raw ICMP ping. NOTE: setting to true requires that it be run with super-user privileges.

type ProtocolVersion

type ProtocolVersion int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL