traceroute

package
v0.0.0-...-e631ab5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: MIT Imports: 11 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ProtocolICMP     = 1
	ProtocolTCP      = 6
	ProtocolUDP      = 17
	ProtocolIPv6ICMP = 58
)

IANA Assigned Internet Protocol Numbers

Variables

View Source
var DefaultConfig = Config{
	Delay:    50 * time.Millisecond,
	Timeout:  2 * time.Second,
	MaxHops:  30,
	Count:    3,
	Networks: []string{"ip4:icmp", "ip4:ip"},
}

DefaultConfig is the default configuration for Tracer.

View Source
var DefaultTracer = &Tracer{
	Config: DefaultConfig,
}

DefaultTracer is a tracer with DefaultConfig.

Functions

This section is empty.

Types

type Config

type Config struct {
	Delay    time.Duration
	Timeout  time.Duration
	MaxHops  int
	Count    int
	Networks []string
	Addr     *net.IPAddr
}

Config is a configuration for Tracer.

type Hop

type Hop struct {
	Nodes    []*Node
	Distance int
}

Hop is a set of detected nodes.

func Trace

func Trace(ip net.IP) ([]*Hop, error)

Trace is a simple traceroute tool using DefaultTracer.

func (*Hop) Add

func (h *Hop) Add(r *Reply) *Node

Add adds node from r.

type Node

type Node struct {
	IP  net.IP
	RTT []time.Duration
}

Node is a detected network node.

type Reply

type Reply struct {
	IP   net.IP
	RTT  time.Duration
	Hops int
}

Reply is a reply packet.

type Session

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

Session is a tracer session.

func NewSession

func NewSession(ip net.IP) (*Session, error)

NewSession returns new session.

func (*Session) Close

func (s *Session) Close()

Close closes tracer session.

func (*Session) Ping

func (s *Session) Ping(ttl int) error

Ping sends single ICMP packet with specified TTL.

func (*Session) Receive

func (s *Session) Receive() <-chan *Reply

Receive returns channel to receive ICMP replies.

type Tracer

type Tracer struct {
	Config
	// contains filtered or unexported fields
}

Tracer is a traceroute tool based on raw IP packets. It can handle multiple sessions simultaneously.

func (*Tracer) Close

func (t *Tracer) Close()

Close closes listening socket. Tracer can not be used after Close is called.

func (*Tracer) NewSession

func (t *Tracer) NewSession(ip net.IP) (*Session, error)

NewSession returns new tracer session.

func (*Tracer) Trace

func (t *Tracer) Trace(ctx context.Context, ip net.IP, h func(reply *Reply)) error

Trace starts sending IP packets increasing TTL until MaxHops and calls h for each reply.

Jump to

Keyboard shortcuts

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