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())
}
}