1
0
mirror of https://github.com/balkian/pingish synced 2024-11-23 03:52:29 +00:00

First commit

This commit is contained in:
J. Fernando Sánchez 2018-10-18 13:09:48 +02:00
commit 011f9e57ce
6 changed files with 74 additions and 0 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
build:
CGO_ENABLED=0 go build -ldflags="-s -w" -o pingish
run: build
./pingish -c 10 -host www.google.es

14
README.md Normal file
View File

@ -0,0 +1,14 @@
Stupidly simple command line tool to resolve and ping hostnames.
I just use the binary to troubleshoot connectivity issues in scratch/alpine containers that don't have ping/dig/curl/wget.
Just copy the binary to the container, and problem solved.
The binary has to be built with `CGO_ENABLED=0` to avoid problems with alpine-based images.
# TROUBLESHOOTING
To run it as a normal user in ubuntu, you might need to configure your host first: `sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"`
And/or set the capabilities of the binary: `sudo setcap cap_net_raw=ep pingish`

6
go.mod Normal file
View File

@ -0,0 +1,6 @@
module github.com/balkian/pingish
require (
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f // indirect
)

4
go.sum Normal file
View File

@ -0,0 +1,4 @@
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:nt2877sKfojlHCTOBXbpWjBkuWKritFaGIfgQwbQUls=
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8=
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f h1:4pRM7zYwpBjCnfA1jRmhItLxYJkaEnsmuAcRtA347DA=
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

45
main.go Normal file
View File

@ -0,0 +1,45 @@
package main
import (
"flag"
"fmt"
"net"
"os"
"time"
"github.com/tatsushid/go-fastping"
)
func main() {
name := flag.String("host", "www.google.es", "Hostname to ping")
count := flag.Int("c", 3, "Number of times to wait for the ")
flag.Parse()
adds, err := net.LookupHost(*name)
if err != nil {
panic(err)
}
fmt.Println("List of addresses:")
for _, add := range adds {
fmt.Println("\t", add)
}
p := fastping.NewPinger()
ra, err := net.ResolveIPAddr("ip4:icmp", *name)
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)
}
for i := 0; i < *count; i++ {
err = p.Run()
if err != nil {
fmt.Println(err)
}
}
fmt.Println("finished")
}

BIN
pingish Executable file

Binary file not shown.