traceroute

package module
v0.0.0-...-2bda1fc Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 5 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

Overview

Package traceroute provides functions for executing a tracroute to a remote host.

Index

Constants

View Source
const (
	// DefaultPort is the default local src port (33434)
	DefaultPort = 33434
	// DefaultMaxHops is the default int of max hops (64)
	DefaultMaxHops = 64
	// DefaultFirstHop is the default first hop (1)
	DefaultFirstHop = 1
	// DefaultTimeoutMs is the default timeout in ms
	DefaultTimeoutMs = 500
	// DefaultRetries is the default number of times to retry
	DefaultRetries = 3
	// DefaultPacketSize is the default packet size
	DefaultPacketSize = 52
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Hop

type Hop struct {
	Success     bool
	Address     [4]byte
	Host        string
	N           int
	ElapsedTime time.Duration
	TTL         int
}

Hop type

func (*Hop) AddressString

func (hop *Hop) AddressString() string

AddressString returns a hop address as a string

func (*Hop) HostOrAddressString

func (hop *Hop) HostOrAddressString() string

HostOrAddressString returns a hostname or address string

type Options

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

Options is the struct for options

func (*Options) FirstHop

func (options *Options) FirstHop() int

FirstHop sets the first hop to track

func (*Options) MaxHops

func (options *Options) MaxHops() int

MaxHops sets the number of max hops

func (*Options) PacketSize

func (options *Options) PacketSize() int

PacketSize sets the packet size

func (*Options) Port

func (options *Options) Port() int

Port sets a local port

func (*Options) Retries

func (options *Options) Retries() int

Retries sets the number of retries

func (*Options) SetFirstHop

func (options *Options) SetFirstHop(firstHop int)

SetFirstHop also sets the first hop to track

func (*Options) SetMaxHops

func (options *Options) SetMaxHops(maxHops int)

SetMaxHops also sets the number of max hops

func (*Options) SetPacketSize

func (options *Options) SetPacketSize(packetSize int)

SetPacketSize also sets the packet size

func (*Options) SetPort

func (options *Options) SetPort(port int)

SetPort also sets a port

func (*Options) SetRetries

func (options *Options) SetRetries(retries int)

SetRetries also sets the number of retries

func (*Options) SetTimeoutMs

func (options *Options) SetTimeoutMs(timeoutMs int)

SetTimeoutMs also sets the default timeout in ms

func (*Options) TimeoutMs

func (options *Options) TimeoutMs() int

TimeoutMs sets the default timeout in ms

type Result

type Result struct {
	DestinationAddress [4]byte
	Hops               []Hop
}

Result is a traceroute result struct

func Traceroute

func Traceroute(dest string, options *Options, c ...chan Hop) (result Result, err error)

Traceroute uses the given dest (hostname) and options to execute a traceroute from your machine to the remote host.

Outbound packets are UDP packets and inbound packets are ICMP.

Returns a Result which contains an array of hops. Each hop includes the elapsed time and its IP address.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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