Comments (9)
tweet見ました!pingu面白いですね🎉
自分の環境がWSL(Debian)なのですが、雑にやってみたことを共有します🙇
概要としては、pinger.SetPrivileged(true)
+ sudo setcap cap_net_raw=+ep path/to/pingu
で、pingu実行できました、という内容です🙋♀️
- 以下は、
ipv4.ping_group_range
の値をデフォルト値に戻して、pinguが失敗する状態に戻し、
16:06:32 > pingu github.com
PING github.com (13.114.40.48) type `Ctrl-C` to abort
... . ... .. .. ......... seq=0 32bytes from 13.114.40.48: ttl=44 time=14.012181ms
... .... .. .. ... ..... .. .. seq=1 32bytes from 13.114.40.48: ttl=44 time=14.069981ms
... ....... ... ... . ..... ####### seq=2 32bytes from 13.114.40.48: ttl=44 time=13.407582ms
..... ........ .###############..... ... ##########. . seq=3 32bytes from 13.114.40.48: ttl=44 time=12.866183ms
.... ........#####################. ... ########### seq=4 32bytes from 13.114.40.48: ttl=44 time=13.314583ms
....... ######################.... ############ seq=5 32bytes from 13.114.40.48: ttl=44 time=13.455982ms
. . .... ########################... ########### seq=6 32bytes from 13.114.40.48: ttl=44 time=14.013181ms
.. ....#########################.. .########### seq=7 32bytes from 13.114.40.48: ttl=44 time=13.393982ms
. #########################. .########## seq=8 32bytes from 13.114.40.48: ttl=44 time=13.824781ms
.... .########################. ######## seq=9 32bytes from 13.114.40.48: ttl=44 time=14.165381ms
^C
───── github.com ping statistics ─────
PACKET STATISTICS: 10 transmitted => 10 received (0% loss)
ROUND TRIP: min=12.866183ms avg=13.652381ms max=14.165381ms stddev=403.038µs
~
16:06:45 > sysctl -n net.ipv4.ping_group_range
0 2147483647
~
16:09:47 >
~
16:09:57 > sudo sysctl -w net.ipv4.ping_group_range="1 0"
[sudo] ochi のパスワード:
net.ipv4.ping_group_range = 1 0
~
16:13:25 > pingu github.com
PING github.com (52.192.72.89) type `Ctrl-C` to abort
[ERROR] an error occurred when running ping: socket: permission denied
~
- pinguのmain.go内を以下に変更し、
func initPinger(host string) (*ping.Pinger, error) {
pinger, err := ping.NewPinger(host)
if err != nil {
return nil, fmt.Errorf("failed to init pinger %w", err)
}
// Listen for Ctrl-C.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
pinger.Stop()
}
}()
color.New(color.FgHiWhite, color.Bold).Printf(
"PING %s (%s) type `Ctrl-C` to abort\n",
pinger.Addr(),
pinger.IPAddr(),
)
pinger.OnRecv = pingerOnrecv
pinger.OnFinish = pingerOnFinish
pinger.SetPrivileged(true)
// ↑を追記し以下をコメントアウト
// if runtime.GOOS == "windows" {
// pinger.SetPrivileged(true)
// }
return pinger, nil
}
go build
して、setcap
を実行してpinguが実行できることを確認しました~
16:34:35 > go build
~/github.com/ddddddO/pingu
16:35:05 > ls | grep pingu
pingu
~/github.com/ddddddO/pingu
16:35:25 > pwd
/home/ochi/github.com/ddddddO/pingu
~/github.com/ddddddO/pingu
16:35:35 > sudo setcap cap_net_raw=+ep /home/ochi/github.com/ddddddO/pingu/pingu
~/github.com/ddddddO/pingu
16:35:40 > ./pingu github.com
PING github.com (52.192.72.89) type `Ctrl-C` to abort
... . ... .. .. ......... seq=0 32bytes from 52.192.72.89: ttl=42 time=10.733279ms
... .... .. .. ... ..... .. .. seq=1 32bytes from 52.192.72.89: ttl=42 time=11.776576ms
... ....... ... ... . ..... ####### seq=2 32bytes from 52.192.72.89: ttl=42 time=10.263379ms
..... ........ .###############..... ... ##########. . seq=3 32bytes from 52.192.72.89: ttl=42 time=10.910478ms
.... ........#####################. ... ########### seq=4 32bytes from 52.192.72.89: ttl=42 time=10.813078ms
....... ######################.... ############ seq=5 32bytes from 52.192.72.89: ttl=42 time=10.704279ms
. . .... ########################... ########### seq=6 32bytes from 52.192.72.89: ttl=42 time=11.123278ms
.. ....#########################.. .########### seq=7 32bytes from 52.192.72.89: ttl=42 time=11.486577ms
^C
───────── github.com ping statistics ─────────
PACKET STATISTICS: 8 transmitted => 8 received (0% loss)
ROUND TRIP: min=10.263379ms avg=10.976365ms max=11.776576ms stddev=446.473µs
~/github.com/ddddddO/pingu
16:36:16 >
from pingu.
細かいところまで調査くださりありがとうございます!✨
とても勉強になります。
sysctl
でシステムの設定を変えなくても、 pinger.SetPrivileged(true)
+ sudo setcap cap_net_raw=+ep path/to/pingu
の方法で行けそうですね。この方針で実装してみたいと思います。
from pingu.
--privilege
オプションを実装しました。
if opts.Privilege || runtime.GOOS == "windows" {
pinger.SetPrivileged(true)
}
WSLでも pingu -P 127.0.0.1
のようにすればたぶん動くと思います。
from pingu.
こちらこそ勉強になりました🌞!
from pingu.
Already surpported in native Windows environment: #2
Thank you, mattn!
if runtime.GOOS == "windows"
pinger.SetPrivileged(true)
}
However, not working in the WSL environment, so it seems that it is necessary to enable privileged mode.
from pingu.
Is there a way to determine from the Go code whether the current environment is native Linux or WSL?
from pingu.
Oops, I accidentally closed the issue.
from pingu.
I have confirmed that it works with WSL under the following conditions. Thank you, kurehajime!
--privilege
: Enable- Execute
sudo setcap cap_net_raw=+ep /path/to/pingu
before runpingu
from pingu.
Thank you everyone for your cooperation! I will close this issue. ☑️
from pingu.
Related Issues (8)
- Add screenshot HOT 1
- How about enable "Github Code Scanning" ? HOT 2
- Why not draw a Kumamon? HOT 1
- Mismatch Go version between go.mod and golangci-lint.yaml HOT 1
- コマンドにIPv6用のオプションの追加 HOT 4
- Force IPv6 HOT 1
- Socket: permission denied HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pingu.