Created
May 4, 2020 09:21
-
-
Save gotohr/8a55b2d287c7bdb4731a70fb3596a623 to your computer and use it in GitHub Desktop.
github.com/tatsushid/go-fastping example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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