pings

command module
v0.0.0-...-4cf7655 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 8 Imported by: 0

README

pings

Shows ping log and statistics in real time.

pinger.png

Installation & Usage

Linux

go get -u github.com/halega/pings
cd ~/go/bin
sudo setcap cap_net_raw+ep pings
pings www.google.com

Windows

git clone https://github.com/halega/pings.git
cd pings
go build
pings www.google.com

Press Ctrl+C to exit.

Libraries

License

MIT

Copyright (c) 2020-present, Stanislav Kalashnikov


Research

Libraries & Projects
sparrc/go-ping API
pinger, _ := ping.NewPinger(host)
defer pinger.Stop()

pinger.OnRecv = func(pkt *ping.Packet) {
	fmt.Printf("%d bytes from %s: icmp_seq=%d time=%v ttl=%v\n",
		pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt, pkt.Ttl)
}
pinger.OnFinish = func(stats *ping.Statistics) {
  fmt.Printf("\n--- %s ping statistics ---\n", stats.Addr)
  fmt.Printf("%d packets transmitted, %d packets received, %v%% packet loss\n",
    stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
  fmt.Printf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
    stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
}
pinger.Count = *count
pinger.Interval = *interval
pinger.Timeout = *timeout
pinger.SetPrivileged(*privileged)

fmt.Printf("PING %s (%s):\n", pinger.Addr(), pinger.IPAddr())
pinger.Run()
digineo/go-ping API
ip, _ := net.ResolveIPAddr("ip4", host)
pinger, _ := ping.New("0.0.0.0", "")
defer pinger.Close()
rtt, err := pinger.Ping(ip, 3*time.Second)
glinton/ping API
ipAddr, _ := net.ResolveIPAddr("ip4", host)
data := bytes.Repeat([]byte{1}, 56)
c := &ping.Client{}
req := ping.Request{
  Dst:  net.ParseIP(host.String()),
  Src:  net.ParseIP(getAddr(*iface)),
  Data: data,
}
ctx, _ := context.WithTimeout(context.Background(), time.Duration(*timeout*float64(time.Second)))
resp, err := c.Do(ctx, &req)
if err != nil {
  fmt.Println("failed to ping:", err)
  return
}
System's Ping Outputs
root@longt:~# ping ya.ru
PING ya.ru(ya.ru (2a02:6b8::2:242)) 56 data bytes
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=1 ttl=52 time=21.5 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=2 ttl=52 time=21.5 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=3 ttl=52 time=21.4 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=4 ttl=52 time=21.6 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=5 ttl=52 time=21.5 ms
^C
--- ya.ru ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 21.485/21.570/21.695/0.199 ms

Summary bar:

64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=1 ttl=52 time=21.5 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=2 ttl=52 time=21.5 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=3 ttl=52 time=21.4 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=4 ttl=52 time=21.6 ms
64 bytes from ya.ru (2a02:6b8::2:242): icmp_seq=5 ttl=52 time=21.5 ms
.............................

-------------------------------------------------------------------------------
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 21.485/21.570/21.695/0.199 ms

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL