mirror of
https://github.com/balkian/pingish
synced 2024-11-21 11:02:29 +00:00
First commit
This commit is contained in:
commit
011f9e57ce
5
Makefile
Normal file
5
Makefile
Normal 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
14
README.md
Normal 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
6
go.mod
Normal 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
4
go.sum
Normal 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
45
main.go
Normal 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")
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user