traceroute

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 16 Imported by: 0

README

Traceroute in Go

A traceroute library written in Go.

Must be run as sudo on OS X (and others)?

CLI App

go build cmd/gotraceroute
sudo ./gotraceroute example.com

Library

See the code in cmd/gotraceroute.go for an example of how to use the library from within your application.

The traceroute.Traceroute() function accepts a domain name and an options struct and returns a TracerouteResult struct that holds an array of TracerouteHop structs.

Resources

Useful resources:

Notes

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingHost error = errors.New("missing host")

ErrMissingHost occurs when we try to process a response for a destination that's not in the list of destinations.

Functions

This section is empty.

Types

type Addr

type Addr struct {
	// Host is the host (ie, DNS) name of the node.
	Host string
	// IP is the IP address of the node.
	IP net.IP
}

type Continuous

type Continuous struct {
	Timeout       time.Duration
	MaxTTL        int
	FirstPort     int
	PortRange     int
	Destinations  []Addr
	Generations   int
	PayloadLength int
	// contains filtered or unexported fields
}

Continuous does a continous traceroute for a set of destinations.

func NewContinuous

func NewContinuous(destinations []string, logger log.Interface) *Continuous

NewContinuous returns a new Continuous for monitoring the supplied destinations using the default options. The supplied Logger, if non-nil, will be used for logging. Invalid destinations will be skipped.

func (*Continuous) Reports

func (c *Continuous) Reports() []Report

func (*Continuous) Run

func (c *Continuous) Run(ctx context.Context) error

Run runs a continous traceroute to the Continuous.Destinations. Except for initialization errors, Run will not return until the supplied context is Done.

type Hop

type Hop struct {
	// Src is the source (ie, local) address.
	Src Addr
	// Dst is the destination (ie, remote) address.
	Dst Addr
	// Node is the node at this step of the route.
	Node Addr
	// Step is the location of this node in the route, ie the TTL value used.
	Step int
	// ID is a unique ID that is used to match the original request with the ICMP response.
	// It can be derived from either the request or the response.
	ID string
	// DstPort is the destination port targeted.
	DstPort int
	// Sent is the time the query began.
	Sent time.Time
	// Received is the time the query completed.
	Received time.Time
	// Elapsed is the duration of the query.
	Elapsed time.Duration
	// Generation is the cycle counter.
	Generation int
	// contains filtered or unexported fields
}

Hop is a step in the network route between a source and destination address.

func (*Hop) Fields

func (r *Hop) Fields() log.Fields

func (*Hop) String

func (r *Hop) String() string

type Report

type Report struct {
	Destination  Addr
	MaxHops      int
	PacketLength int
	Hops         []*Hop
	Generations  int
}

func (Report) String

func (r Report) String() string

Jump to

Keyboard shortcuts

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