mirror of
https://github.com/pnx/pinger.git
synced 2026-06-16 15:30:02 +02:00
Compare commits
No commits in common. "main" and "v0.0.3" have entirely different histories.
5 changed files with 8 additions and 88 deletions
3
.github/workflows/release.yml
vendored
3
.github/workflows/release.yml
vendored
|
|
@ -13,9 +13,6 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ linux, darwin, windows ]
|
os: [ linux, darwin, windows ]
|
||||||
arch: [ amd64, 386 ]
|
arch: [ amd64, 386 ]
|
||||||
exclude:
|
|
||||||
- os: darwin
|
|
||||||
arch: 386
|
|
||||||
name: Release - ${{matrix.os}}-${{matrix.arch}}
|
name: Release - ${{matrix.os}}-${{matrix.arch}}
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
21
LICENSE
21
LICENSE
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
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
|
|
||||||
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.
|
|
||||||
58
README.md
58
README.md
|
|
@ -1,58 +0,0 @@
|
||||||
# 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.
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,6 +1,6 @@
|
||||||
module pinger
|
module pinger
|
||||||
|
|
||||||
go 1.20
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/pborman/getopt/v2 v2.1.0
|
github.com/pborman/getopt/v2 v2.1.0
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -12,7 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// printStats prints statistics from a ping.
|
// printStats prints statistics from a ping.
|
||||||
func printStats(stats *probing.Statistics) {
|
func printStats(pinger *probing.Pinger) {
|
||||||
|
stats := pinger.Statistics()
|
||||||
|
|
||||||
fmt.Printf("%d packets transmitted, %d packets received, %.2f%% packet loss\n",
|
fmt.Printf("%d packets transmitted, %d packets received, %.2f%% packet loss\n",
|
||||||
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
||||||
|
|
||||||
|
|
@ -32,11 +34,11 @@ func eventLoop(pinger *probing.Pinger, ticker *time.Ticker) {
|
||||||
select {
|
select {
|
||||||
// Got signal. stop pinger and exit goroutine
|
// Got signal. stop pinger and exit goroutine
|
||||||
case s := <-sig:
|
case s := <-sig:
|
||||||
fmt.Printf("Recived signal: %s, exiting.\n", s)
|
fmt.Printf("Recived signal: %s, exiting.", s)
|
||||||
return
|
return
|
||||||
// Ticker ticks. print stats.
|
// Ticker ticks. print stats.
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
printStats(pinger.Statistics())
|
printStats(pinger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +59,7 @@ func main() {
|
||||||
getopt.Parse()
|
getopt.Parse()
|
||||||
|
|
||||||
if *version {
|
if *version {
|
||||||
fmt.Println("Version 0.0.4")
|
fmt.Println("Version 0.0.3")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +80,6 @@ func main() {
|
||||||
pinger.Source = *source
|
pinger.Source = *source
|
||||||
pinger.Count = *count
|
pinger.Count = *count
|
||||||
pinger.RecordRtts = *record_rtt
|
pinger.RecordRtts = *record_rtt
|
||||||
pinger.OnFinish = printStats
|
|
||||||
if timeout != nil && *timeout > 0 {
|
if timeout != nil && *timeout > 0 {
|
||||||
pinger.Timeout = *timeout
|
pinger.Timeout = *timeout
|
||||||
}
|
}
|
||||||
|
|
@ -90,5 +91,6 @@ func main() {
|
||||||
fmt.Println("PING", pinger.Addr())
|
fmt.Println("PING", pinger.Addr())
|
||||||
if err = pinger.Run(); err != nil {
|
if err = pinger.Run(); err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue