Skip to content

Instantly share code, notes, and snippets.

@gotohr
Created May 4, 2020 09:21
Show Gist options
  • Save gotohr/8a55b2d287c7bdb4731a70fb3596a623 to your computer and use it in GitHub Desktop.
Save gotohr/8a55b2d287c7bdb4731a70fb3596a623 to your computer and use it in GitHub Desktop.
github.com/tatsushid/go-fastping example
package main
import (
"fmt"
"net"
"os"
"time"
"github.com/tatsushid/go-fastping"
)
func main() {
p := fastping.NewPinger()
ra, err := net.ResolveIPAddr("ip4:icmp", os.Args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
p.AddIPAddr(ra)
p.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
fmt.Printf("IP Addr: %s receive, RTT: %v\n", addr.String(), rtt)
}
p.OnIdle = func() {
fmt.Println("finish")
}
err = p.Run()
if err != nil {
fmt.Println(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment