klw-account2 d6dae3bab7 feature: 增加网络诊断服务 | 2 weeks ago | |
---|---|---|
.. | ||
pb | 2 weeks ago | |
NetworkDiagnosticServer.go | 2 weeks ago | |
ping_test.go | 2 weeks ago | |
readme.md | 2 weeks ago |
This library attempts to send an "unprivileged" ping via UDP. On Linux, this must be enabled with the following sysctl command:
sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
If you do not wish to do this, you can call pinger.SetPrivileged(true)
in your code and then use setcap on your binary to allow it to bind to raw sockets (or just run it as root):
setcap cap_net_raw=+ep /path/to/your/compiled/binary
See this blog and the Go x/net/icmp package for more details.
You must use pinger.SetPrivileged(true)
, otherwise you will receive the following error:
socket: The requested protocol has not been configured into the system, or no implementation for it exists.
Despite the method name, this should work without the need to elevate privileges and has been tested on Windows 10. Please note that accessing packet TTL values is not supported due to limitations in the Go x/net/ipv4 and x/net/ipv6 packages.
There is no support for Plan 9. This is because the entire x/net/ipv4
and x/net/ipv6
packages are not implemented by the Go programming language.