https://github.com/glinton/ping
Simple golang ping library patterned after net/http.
https://github.com/glinton/ping
go network ping
Last synced: 5 months ago
JSON representation
Simple golang ping library patterned after net/http.
- Host: GitHub
- URL: https://github.com/glinton/ping
- Owner: glinton
- License: mit
- Created: 2019-06-12T21:53:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-24T23:23:59.000Z (over 3 years ago)
- Last Synced: 2024-06-18T23:13:33.343Z (about 2 years ago)
- Topics: go, network, ping
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ping
[](https://godoc.org/github.com/glinton/ping)
Simple (ICMP) library patterned after net/http.
Originally inspired by [sparrc/go-ping](https://github.com/sparrc/go-ping)
### Installation
```sh
go get -du github.com/glinton/ping
```
To install an all-go iputils patterned `ping` binary
```sh
go get github.com/glinton/ping/cmd/ping
# to run:
$GOPATH/bin/ping localhost
```
### Example
```go
package main
import (
"context"
"fmt"
"github.com/glinton/ping"
)
func main() {
res, err := ping.IPv4(context.Background(), "google.com")
if err != nil {
panic(err)
}
fmt.Printf("Completed one ping to google.com with %d bytes in %v\n",
res.TotalLength, res.RTT)
}
```
### Notes Regarding ICMP Socket Permissions
System installed `ping` binaries generally have `setuid` attributes set, thus allowing them to utilize privileged ICMP sockets. This should work for applications built with this library as well, but a better approach would be to give the application the capability to create privileged ICMP sockets. To do so, run the following as the `root` user (not applicable to Windows).
```
setcap cap_net_raw=eip /path/to/your/application
```
This library tries to initialize a privileged ICMP socket before falling back to unprivileged raw sockets on Linux and Darwin (`udp4` or `udp6` as the network). On Linux, the system group of the user running the application must be allowed to create unprivileged ICMP sockets if desired. [See man pages icmp(7) for `ping_group_range`](http://man7.org/linux/man-pages/man7/icmp.7.html).
To allow a range of groups access to create unprivileged icmp sockets on linux (ipv4 or ipv6), run:
```
sudo sysctl -w net.ipv4.ping_group_range="GROUPID_START GROUPID_END"
```
If you plan to run your application as `root`, the aforementioned commmand is not necessary.
On Windows, running a terminal as admin should not be necessary.
### Known Issues
There is currently no support for TTL on windows, track progress at https://github.com/golang/go/issues/7175 and https://github.com/golang/go/issues/7174
Report any other issues you may find [here](https://github.com/glinton/ping/issues/new)