From 111ff58fcf5a3a12dfacf00cae521ee6099a54c0 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 30 May 2025 16:44:19 +0200 Subject: [PATCH 01/10] .github/workflows/release.yml: exclude darwin 386 --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf9b38a..a198643 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,9 @@ jobs: matrix: os: [ linux, darwin, windows ] arch: [ amd64, 386 ] + exclude: + - os: darwin + arch: 386 name: Release - ${{matrix.os}}-${{matrix.arch}} runs-on: ubuntu-24.04 steps: From 5571ba3f38aecb8292f773f7d519879648acc02b Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:16:22 +0200 Subject: [PATCH 02/10] go.mod: set minimum version to 1.20 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 3598691..d240580 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module pinger -go 1.19 +go 1.20 require ( github.com/pborman/getopt/v2 v2.1.0 From 27479462641995309a91739781a92a4b39e02370 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:16:33 +0200 Subject: [PATCH 03/10] add README and LICENSE --- LICENSE | 21 ++++++++++++++++++++ README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..349c2d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023-2025 Henrik Hautakoski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a21d42 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# Pinger + +**Pinger** is a lightweight, high-performance network utility written in Go. +It enables users to send ICMP echo requests (pings) to specified hosts, facilitating network diagnostics and monitoring. + +## Features + +* Send ICMP echo requests to specified hosts. +* Measure round-trip time (RTT) for each ping. +* Support for both IPv4 and IPv6 addresses. +* Configurable number of ping attempts and intervals. +* Lightweight and efficient, suitable for scripting and automation. + +## Installation + +### Prerequisites + +* Go (version 1.20 or later) installed on your system. +* make + +### Steps + +1. Clone the repository: + +```bash +git clone https://github.com/pnx/pinger.git +cd pinger +``` + +2. Build the application: + +```bash +make +``` + +## Usage + +See `./pinger -h` + +### Example + +```bash +./pinger --udp -t 30s example.com +``` + +This command sends UDP echo requests to example.com, stopping after 30 seconds + +```bash +./pinger -c 8 -i 1s example.com +``` + +This command sends 8 ICMP echo requests to example.com, with a 1-second interval between pings. +NOTE: this requires root privileges + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. From 57a969561e09adee82da4bdf9872c8078b37ca94 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:24:25 +0200 Subject: [PATCH 04/10] main.go: make printStats() take a probing.Statistics object. --- main.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 69c24a2..5ae0c37 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,7 @@ import ( ) // printStats prints statistics from a ping. -func printStats(pinger *probing.Pinger) { - stats := pinger.Statistics() - +func printStats(stats *probing.Statistics) { fmt.Printf("%d packets transmitted, %d packets received, %.2f%% packet loss\n", stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss) @@ -38,7 +36,7 @@ func eventLoop(pinger *probing.Pinger, ticker *time.Ticker) { return // Ticker ticks. print stats. case <-ticker.C: - printStats(pinger) + printStats(pinger.Statistics()) } } } From fffed4e4e1255a29aa865334dea95ed838063292 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:24:50 +0200 Subject: [PATCH 05/10] main.go: set printStatus as OnFinish callback to pinger. --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 5ae0c37..f449cac 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,7 @@ func main() { pinger.Source = *source pinger.Count = *count pinger.RecordRtts = *record_rtt + pinger.OnFinish = printStats if timeout != nil && *timeout > 0 { pinger.Timeout = *timeout } From 7870fc361ae8acd01ac7a35692842cc7684d3f0e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:27:17 +0200 Subject: [PATCH 06/10] main.go: cleanup signal output by printing a newline at the end. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index f449cac..d6e8521 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func eventLoop(pinger *probing.Pinger, ticker *time.Ticker) { select { // Got signal. stop pinger and exit goroutine case s := <-sig: - fmt.Printf("Recived signal: %s, exiting.", s) + fmt.Printf("Recived signal: %s, exiting.\n", s) return // Ticker ticks. print stats. case <-ticker.C: From a4343fa706cb95ce95fd45769b5ba8578518c2fd Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 31 May 2025 17:34:38 +0200 Subject: [PATCH 07/10] README.md: minor fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6a21d42..71dd48d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ This command sends UDP echo requests to example.com, stopping after 30 seconds ``` This command sends 8 ICMP echo requests to example.com, with a 1-second interval between pings. + NOTE: this requires root privileges ## License From b9c0d0b416a925cb8f243f2687307dd743bc065e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 11 May 2026 17:33:52 +0200 Subject: [PATCH 08/10] main.go: no need to return as it's the last statement --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index d6e8521..679d133 100644 --- a/main.go +++ b/main.go @@ -90,6 +90,5 @@ func main() { fmt.Println("PING", pinger.Addr()) if err = pinger.Run(); err != nil { fmt.Println("Error:", err) - return } } From 26de4fa64730260bdb455908fe484c43e203fdbe Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 11 May 2026 17:35:28 +0200 Subject: [PATCH 09/10] v0.0.4 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 679d133..d3f7f20 100644 --- a/main.go +++ b/main.go @@ -57,7 +57,7 @@ func main() { getopt.Parse() if *version { - fmt.Println("Version 0.0.3") + fmt.Println("Version 0.0.4") os.Exit(0) } From 30cee15b1986ab6cab773e0bdfcb4997a2661869 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 11 May 2026 18:07:14 +0200 Subject: [PATCH 10/10] LICENSE: update copyright year to 2026 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 349c2d8..965f691 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023-2025 Henrik Hautakoski +Copyright (c) 2023-2026 Henrik Hautakoski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal