traceroute

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 10 Imported by: 0

README

Traceroute

This library allows to record a traceroute.

Requirements

To execute the traceroute, a privileged port must be opened. this requires special permissions. One possibility is .

A prerequisite for reading incoming traffic is being able to either to be root or set the executable capability CAP_NET_RAW.

Reminder: You can set the CAP_NET_RAW capability on an executable like this:

sudo setcap cap_net_raw+ep /path/to/executable

Look at manpage for setcap

You can also change the restrictions on unprivileged ports.

sudo /sbin/sysctl -w net.ipv4.ip_unprivileged_port_start=0

for the purpose of debugging, pkttyagent can also be taken.


# PID is the processid
pkttyagent --process  PID-OF-IDE

## für netbeans
pkttyagent --process  $(ps -xa | grep "netbeans" )

## für intellij
pkttyagent --process  $(ps -xa | grep "IntelliJ-IDEA-Ultimate/jbr/bin/java" )

Test

/etc/sudoers has restricted PATH environment variable.

When you run sudo make test, /usr/local/go/bin must be entered in secure_path.

Defaults   secure_path="....:/usr/local/go/bin"

Installation

The recommended way to install this package is

go get gitlab.schukai.com/oss/libraries/go/network/traceroute

Usage

First, a session must be created traceroute.NewSession(host). Then the traceroute can be executed session.TraceRoute().

Either waits for the result and continues working with it, or
Specifies a callback that is called directly after a hop.

package main

import (
	"flag"
	"fmt"
	"gitlab.schukai.com/oss/libraries/go/network/traceroute"
)

const (
	flagValue = ""
	flagUsage = "hostname or ip address"
)

func main() {

	var host string

	flag.StringVar(&host, "h", flagValue, flagUsage+" (shorthand)")
	flag.StringVar(&host, "host", flagValue, flagUsage)
	flag.Parse()

	if host == "" {
		fmt.Println("missing host")
		flag.Usage()
		return
	}

	session, err := traceroute.NewSession(host)
	if err != nil {
		flag.Usage()
		return
	}

	session.CallBack = func(result traceroute.Result) {
		if result.Err!=nil {
			fmt.Printf("%v\t%s\t\t\t\t%v\t\t(%s)\n", result.Hop, result.Station, result.Latency, result.Err.Error())
			return
		}
		
		fmt.Printf("%v\t%s\t\t\t%v\n", result.Hop, result.Station, result.Latency)
	}

	_, err=session.TraceRoute()
	if err!=nil {
		fmt.Println(err.Error())
	}

}

Documentation

Index

Constants

View Source
const (
	ProtocolIPv6ICMP = 58 // ICMP for IPv6
	ProtocolICMP     = 1  // Internet Control Message
)

from internal/iana/const.go Protocol Numbers, Updated: 2017-10-13

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Hop     int
	Station string
	Latency time.Duration
	Err     error
}

Result holds the data

type Results

type Results struct {
	Hops []Result
}

Results is a collection of hops

type Session

type Session struct {
	Destination *address
	Source      *address

	CallBack func(result Result)

	Timeout time.Duration `default:"5"` // in seconds
	MaxHops int           `default:"30"`

	Mode int
	// contains filtered or unexported fields
}

Session is Transaction Struct

func NewSession

func NewSession(destination string) (*Session, error)

NewSession creates a new Session

func (*Session) TraceRoute

func (s *Session) TraceRoute() (*Results, error)

TraceRoute measures the steps to the target host

func (*Session) TraceRouteV4

func (s *Session) TraceRouteV4() (*Results, error)

TraceRouteV4 run V4 Traceroute

func (*Session) TraceRouteV6

func (s *Session) TraceRouteV6() (*Results, error)

TraceRouteV6 run V6 trace

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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