traceroute

package module
v0.0.0-...-f710a11 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 6 Imported by: 0

README

Traceroute in Go

A traceroute library written in Go.

Build Status Go Report Card GoDoc

Forked from aeden/traceroute.

CLI App

go install github.com/smallnest/traceroute/cmd/tracert
sudo tracert 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

View Source
const (
	DEFAULT_PORT        = 33434
	DEFAULT_MAX_HOPS    = 64
	DEFAULT_FIRST_HOP   = 1
	DEFAULT_TIMEOUT_MS  = 500
	DEFAULT_NQUERIES    = 1
	DEFAULT_PACKET_SIZE = 0
)

Variables

View Source
var DefaultOption = &Option{
	port:         DEFAULT_PORT,
	maxHops:      DEFAULT_MAX_HOPS,
	firstHop:     DEFAULT_FIRST_HOP,
	timeoutMs:    DEFAULT_TIMEOUT_MS,
	nqueries:     DEFAULT_NQUERIES,
	packetSize:   DEFAULT_PACKET_SIZE,
	privileged:   true,
	fixedDstPort: false,
}

DefaultOption provides a default opt.

Functions

This section is empty.

Types

type Hop

type Hop struct {
	Success     bool
	Address     net.Addr
	Host        string
	N           int
	ElapsedTime time.Duration
	TTL         int
}

Hop type

func (*Hop) AddressString

func (hop *Hop) AddressString() string

func (*Hop) String

func (hop *Hop) String() string

type Option

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

TracrouteOption type

func (*Option) DisableFixedDstPort

func (opt *Option) DisableFixedDstPort()

func (*Option) DisablePrivileged

func (opt *Option) DisablePrivileged()

func (*Option) DisableResolveHost

func (opt *Option) DisableResolveHost()

func (*Option) EnableFixedDstPort

func (opt *Option) EnableFixedDstPort()

func (*Option) EnablePrivileged

func (opt *Option) EnablePrivileged()

func (*Option) EnableResolveHost

func (opt *Option) EnableResolveHost()

func (*Option) FirstHop

func (opt *Option) FirstHop() int

func (*Option) FixedDstPort

func (opt *Option) FixedDstPort() bool

func (*Option) MaxHops

func (opt *Option) MaxHops() int

func (*Option) NRequeries

func (opt *Option) NRequeries() int

func (*Option) PacketSize

func (opt *Option) PacketSize() int

func (*Option) Port

func (opt *Option) Port() int

func (*Option) Privileged

func (opt *Option) Privileged() bool

func (*Option) ResolveHost

func (opt *Option) ResolveHost() bool

func (*Option) SetFirstHop

func (opt *Option) SetFirstHop(firstHop int)

func (*Option) SetMaxHops

func (opt *Option) SetMaxHops(maxHops int)

func (*Option) SetNRequeries

func (opt *Option) SetNRequeries(nqueries int)

func (*Option) SetPacketSize

func (opt *Option) SetPacketSize(packetSize int)

func (*Option) SetPort

func (opt *Option) SetPort(port int)

func (*Option) SetTimeoutMs

func (opt *Option) SetTimeoutMs(timeoutMs int)

func (*Option) TimeoutMs

func (opt *Option) TimeoutMs() int

type TraceResult

type TraceResult struct {
	DestinationAddress string
	Hops               []Hop
}

TraceResult type

func Trace

func Trace(dest string, opt *Option, c ...chan Hop) (result TraceResult, err error)

Trace uses the given dest (hostname) and option to execute a traceroute from your machine to the remote host by using golang.org/x/net/icmp.

Outbound packets are UDP packets and inbound packets are ICMP.

Returns a TracerouteResult 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