icmp

package module
v0.0.0-...-5f8f07e Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

icmp

golang icmp for simple use

Documentation

Index

Constants

View Source
const (
	ICMPv4 = 1
	ICMPv6 = 58
)

proto

Variables

This section is empty.

Functions

This section is empty.

Types

type EchoStat

type EchoStat struct {
	Seq  int
	TTL  int
	Cost time.Duration
	Err  error
}

EchoStat echo reply stat

type ICMP

type ICMP struct {
	ID int
	// contains filtered or unexported fields
}

ICMP icmp config

func New

func New(opts ...Option) *ICMP

New ping

func (*ICMP) Echo

func (i *ICMP) Echo(ctx context.Context, addr *net.IPAddr, seq int, options Options) (*EchoStat, error)

func (*ICMP) Ping

func (i *ICMP) Ping(ctx context.Context, host string, opts ...Option) (*Statistics, error)

Ping without stdout

type Option

type Option func(*Options)

Option Options function

func Count

func Count(count int) Option

Count count

func Log

func Log(f func(string, ...any)) Option

Log ..

func Size

func Size(size int) Option

Size set size

func Timeout

func Timeout(timeout time.Duration) Option

Timeout set timeout

func Wait

func Wait(wait time.Duration) Option

Wait seconds between sending each packet.

type Options

type Options struct {
	Log func(string, ...interface{})

	// Timeout (-W) 参数用于设置单个ICMP回显请求等待回应的超时时间,单位通常也是秒。
	// 如果在指定的时间内没有收到回应,该ICMP请求就会被认为是丢失的。
	// 例如:ping -W 2 192.168.1.1
	// 这个命令将对192.168.1.1进行ping操作,每次发送请求后,如果2秒内没有收到回应,则该请求超时。
	Timeout time.Duration // send packet timeout
	// contains filtered or unexported fields
}

Options options

type Statistics

type Statistics struct {
	Host        string
	Transmitted int
	Received    int
	Loss        float64
	Time        time.Duration // total cost, only compute send packet
	TimeExp2    int64
	// contains filtered or unexported fields
}

Statistics ..

func (*Statistics) Print

func (stats *Statistics) Print() string

Print print

func (*Statistics) String

func (stats *Statistics) String() string

Jump to

Keyboard shortcuts

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