pingttl

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 10 Imported by: 2

README

go-ping-ttl

Utility library for sending ICMP pings to IPv4 or IPv6 destinations with TTL control.

Actions Status Coverage GitHub last commit GitHub issues GitHub pull requests License Status


Usage

  1. Create an instance of the Pinger with pingttl.New()
  2. Call .Ping() with a context and the address of the host you want to ping.

Your entire application should have a single instance of Pinger. Store it globally (🤢), or preferably, inject it as a dependency!

pinger := pingttl.New()

ip, err := net.ResolveIPAddr("ip4", "google.com")
if err != nil {
    return err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5)
defer cancel()

// Providing 0 as a TTL will default to a sane value (64)
res, err := pinger.Ping(ctx, ip, 0)
if err != nil {
    return err
}

log.Printf("%s", res.Duration)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DestinationUnreachableErr

type DestinationUnreachableErr struct {
	Peer     net.Addr
	Duration time.Duration
}

func (DestinationUnreachableErr) Error

type PingResult

type PingResult struct {
	Duration time.Duration
}

type Pinger

type Pinger struct {

	// Logf is called by the library when it wants to log a warning or error.
	// By default, this produces no output.
	Logf func(string, ...interface{})
	// contains filtered or unexported fields
}

func New

func New() *Pinger

func (*Pinger) Ping

func (p *Pinger) Ping(ctx context.Context, dst *net.IPAddr, ttl int) (*PingResult, error)

func (*Pinger) Run

func (p *Pinger) Run(ctx context.Context) error

type Proto

type Proto int
var (
	ProtoICMPv4 Proto = 1
	ProtoICMPv6 Proto = 58
)

type TimeExceededErr

type TimeExceededErr struct {
	Peer     net.Addr
	Duration time.Duration
}

func (TimeExceededErr) Error

func (e TimeExceededErr) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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