Skip to content

Go implementation of concurrent traceroute on single socket

License

Notifications You must be signed in to change notification settings

pixelbender/go-traceroute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-traceroute

Go implementation of traceroute.

Build Status Go Report Card GoDoc

Features

  • Reusable and Concurrent raw IP socket (needs root)
  • IPv4 ID and IPv6 FlowLabel tracking
  • ICMPv6 support
  • UDP/TCP support
  • Remove golang.org/x/net

Installation

go get github.com/pixelbender/go-traceroute/...

Simple tracing

package main

import (
	"github.com/pixelbender/go-traceroute/traceroute"
	"log"
)

func main() {
    hops, err := traceroute.Trace(net.ParseIP("1.1.1.1"))
    if err != nil {
        log.Fatal(err)
    }
    for _, h := range hops {
        for _, n := range h.Nodes {
            log.Printf("%d. %v %v", h.Distance, n.IP, n.RTT)
        }
    }
}

Custom configuration

package main

import (
	"github.com/pixelbender/go-traceroute/traceroute"
	"context"
	"log"
	"net"
	"time"
)

func main() {
    t := &traceroute.Tracer{
        Config: traceroute.Config{
            Delay:   50 * time.Millisecond,
            Timeout: time.Second,
            MaxHops: 30,
            Count:   3,
            Networks: []string{"ip4:icmp", "ip4:ip"},
        },
    }
    defer t.Close()
    err := t.Trace(context.Background(), net.ParseIP("1.1.1.1"), func(reply *traceroute.Reply) {
        log.Printf("%d. %v %v", reply.Hops, reply.IP, reply.RTT)
    })
    if err != nil {
        log.Fatal(err)
    }
}

About

Go implementation of concurrent traceroute on single socket

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages