Skip to content

Instantly share code, notes, and snippets.

@Hipska
Created July 25, 2024 08:41
Show Gist options
  • Save Hipska/6c19e707445029cae8abfac098405032 to your computer and use it in GitHub Desktop.
Save Hipska/6c19e707445029cae8abfac098405032 to your computer and use it in GitHub Desktop.
Implement trace route with pro-bing
package main
import (
probing "github.com/prometheus-community/pro-bing"
)
func main() {
pinger, err := probing.NewPinger("reddit.com")
if err != nil {
panic(err)
}
//pinger.Count = 3
pinger.TTL = 2
err = pinger.Run() // Blocks until finished.
if err != nil {
panic(err)
}
stats := pinger.Statistics() // get send/receive/duplicate/rtt stats
println(
stats.PacketsRecv,
stats.PacketsSent,
stats.PacketsRecvDuplicates,
stats.PacketLoss,
stats.IPAddr.String(),
stats.Addr,
stats.MinRtt,
stats.MaxRtt,
stats.AvgRtt,
stats.StdDevRtt)
for i, rtt := range stats.Rtts {
println(i, rtt)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment