net

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example
stopChan := make(chan bool, 2)
p := NewPing(stopChan)
if err := p.Start(); err != nil {
	log.Fatalf("start nping failed, %v", err)
}

targets := []string{"127.0.0.1", "example.com"}

networkTargets := make([]*protocol.NetworkTarget, 0, len(targets))
for _, t := range targets {
	networkTargets = append(networkTargets, protocol.ResolveTarget(t))
}
wg := sync.WaitGroup{}
for _, target := range networkTargets {
	wg.Add(1)
	go func(t *protocol.NetworkTarget) {
		defer wg.Done()
		rtt, err := p.PingOnce(t, time.Second)
		if err != nil {
			log.Printf("ping %s error, %v\n", t.Raw, err)
		} else {
			log.Printf("ping %s rtt = %v\n", t.Raw, rtt)
		}
	}(target)
}
wg.Wait()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NPing

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

NPing network ping

func NewPing

func NewPing(stopChan chan bool) *NPing

NewPing new a ping

func (*NPing) PingOnce

func (p *NPing) PingOnce(target *protocol.NetworkTarget, timeout time.Duration) (time.Duration, error)

PingOnce to target with address as `addr`

func (*NPing) Start

func (p *NPing) Start() (err error)

Start listen

func (*NPing) Trace

func (p *NPing) Trace(target *protocol.NetworkTarget, ttl int, timeout time.Duration) (time.Duration, net.Addr, error)

Trace to target with address as `addr`

Directories

Path Synopsis
tcp

Jump to

Keyboard shortcuts

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