-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support root-less ICMP pings on MacOS and Linux #10
Comments
Thanks for the information. I will look into this issue and see what I can do with it. In another hand, I'd love to keep ping3 as an universal solution on all platforms by using python standard libraries. I had to investigate carefully before implementing any platform-specified codes. |
In favour of being root-less if possible. Want to use an "if ping then do X on server" approach and would not feel comfortable running as root, specially when pinging from command line works. Forced to use a workaround like opening a subprocess: https://stackoverflow.com/questions/2953462/pinging-servers-in-python |
It also needs root privilege in linux, I catch the following errors in my Ubuntu 18.04:
|
@clockzhong please read my post carefully and verify that your kernel and groups have been configured correctly:
|
@mjpieters Thanks for your response. Ok, got it, it means even we could use "ping" command for any user in linux, but it has some special work done in linux "ping" command, we also need do the same work for our own python ping program. |
On Ubuntu, if |
Now with a fallback strategy, socket will be created as When SOCK_DGRAM is used on Linux, reset expected ICMP ID from the sock. This should resolve the ICMP ID rewrite problem. |
This feature is done by version>=2.9.1 |
Provided the Linux kernel is configured to allow non-raw ICMP for your group ID (on macOS it is available by default, you can use a
SOCK_DGRAM
socket to ping without being root.I can demonstrate this on my macOS system:
Linux enforces a suitable ICMP ID and checksum for you; there is no point in generating your own checksum (it is ignored and re-calculated) and you should not check for the ICMP ID when receiving packets as the kernel routes the packets to your socket based on their internal bookkeeping, instead.
I haven't found any proof that macOS does this however, so some platform-specific code would be needed to handle this difference. This can be as simple as ignoring the ICMP id when on Linux and not root.
Also see the Linux
man 7 icmp
documentation.Could support for this be implemented in ping3?
The text was updated successfully, but these errors were encountered: