/tracer

Network diagnostic tool in Go inspired from Traceroute.

Primary LanguageGoMIT LicenseMIT

Tracer

Network diagnostic tool in Go inspired by Traceroute.

Makes UDP call to target host increasing the TTL(hops) of IP packet and recording the ICMP response for each hop(router address) until it finally reaches the destination or max TTL is reached.

1. CLI

go install github.com/nirdosh17/tracer/cmd/gotrace@latest

You can find the binaries HERE.

Examples:

# tracing requires privileged access
sudo gotrace example.com

# with options (max hops, timeout, retries)
sudo gotrace -hops 5 -t 5 -r 5 example.com

# get your public ip
gotrace myip

# view command details
gotrace -help

Get public IP:

Get IP

Trace route:

Traceroute

2. Use as a lib

Install Package:

go get github.com/nirdosh17/tracer
package main

import (
  "fmt"
  "sync"

  "github.com/nirdosh17/tracer"
)

func main() {
  host := "example.com"

  var wg sync.WaitGroup
  wg.Add(1)
  c := make(chan tracer.Hop)
  go liveReader(&wg, c)

  t := tracer.NewTracer(tracer.NewConfig())
  _, err := t.Run(host, c)
  if err != nil {
    fmt.Println("trace err: ", err)
  }
  wg.Wait()
}

// read live hops from channel
func liveReader(wg *sync.WaitGroup, c chan tracer.Hop) {
  for {
    hop, ok := <-c
    // channel closed
    if !ok {
      wg.Done()
      return
    }
    fmt.Printf("%v.   %v    %v    %v\n", hop.TTL, hop.Addr, hop.Location, hop.ElapsedTime)
  }
}