ping

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package ping contains utility functions to wrap around the ping program.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(c *config)

Option is a function used to configure ping command.

func BindAddress

func BindAddress(bind bool) Option

BindAddress returns an Option that can be passed to Ping to disallow ping from changing source address.

func Count

func Count(count int) Option

Count returns an Option that can be passed to Ping func to set ping count.

func Interval

func Interval(interval float64) Option

Interval returns an Option that can be passed to Ping to set interval (in seconds).

func QOS

func QOS(qos QOSType) Option

QOS returns an Option that can be passed to Ping to set QOS type.

func SaveOutput

func SaveOutput(filePath string) Option

SaveOutput returns an Option that can be passed to Ping to save the output of ping command to filePath under OutDir.

func Size

func Size(size int) Option

Size returns an Option that can be passed to Ping to set packet size.

func SourceIface

func SourceIface(iface string) Option

SourceIface returns an Option that can be passed to Ping to set source interface.

func User

func User(user string) Option

User returns an Option that can be passed to Ping to set user.

type QOSType

type QOSType int

QOSType is a enum type for ping QOS option.

const (
	QOSBK QOSType = 0x02
	QOSBE QOSType = 0x04
	QOSVI QOSType = 0x08
	QOSVO QOSType = 0x10
)

Enum of QOSType.

type Result

type Result struct {
	Sent       int
	Received   int
	Loss       float64
	MinLatency float64
	AvgLatency float64
	MaxLatency float64
	DevLatency float64
}

Result is a struct that contains a successful ping's statistics.

type Runner

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

Runner is the object contains ping utilities.

func NewRunner

func NewRunner(c cmd.Runner) *Runner

NewRunner creates a new ping command utility runner.

func (*Runner) Ping

func (r *Runner) Ping(ctx context.Context, targetIP string, options ...Option) (*Result, error)

Ping performs a shell ping with parameters specified in Options. If no Option is specified, default config (count=10, interval=0.5s) is used. Notice that when no reply is received, this function will try to parse the output and return a valid result instead of returning the error of non-zero return code of ping.

Jump to

Keyboard shortcuts

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