Skip to content

Instantly share code, notes, and snippets.

@wayt
Created May 11, 2016 14:12
Show Gist options
  • Save wayt/7788d6c94b5e28001fa9872e0bef0050 to your computer and use it in GitHub Desktop.
Save wayt/7788d6c94b5e28001fa9872e0bef0050 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"net"
"os"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
if len(os.Args) < 2 {
fmt.Printf("Usage: ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]\n\t[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]\n\t[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]\n\t[-w deadline] [-W timeout] [hop1 ...] destination\n")
return
}
target := os.Args[1]
ip, err := net.ResolveIPAddr("ip4", target)
if err != nil {
fmt.Printf("error: %v\n", err)
os.Exit(1)
}
fmt.Printf("PING %s (%s) 56(84) bytes of data.\n", target, ip.String())
for i := 0; ; i++ {
ms := (float64(rand.Intn(154)) / 10)
fmt.Printf("64 bytes from %s: icmp_seq=%d ttl=54 time=%.1f ms\n", ip.String(), i+1, ms)
time.Sleep(time.Second - (time.Millisecond * time.Duration(ms)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment