ValentinBELYN / icmplib

Easily forge ICMP packets and make your own ping and traceroute.
GNU Lesser General Public License v3.0
267 stars 45 forks source link

ping(..., privileged=False) not working as expected #31

Closed David-Lor closed 3 years ago

David-Lor commented 3 years ago

Tried launching a ping with the privileged=False option, but still throws a SocketPermissionError:

>>> ping("8.8.8.8", privileged=False)
Traceback (most recent call last):
  File "/home/david/.miniconda3/envs/ping2mqtt/lib/python3.8/site-packages/icmplib/sockets.py", line 88, in __init__
    self._sock = self._create_socket(
  File "/home/david/.miniconda3/envs/ping2mqtt/lib/python3.8/site-packages/icmplib/sockets.py", line 452, in _create_socket
    return socket.socket(
  File "/home/david/.miniconda3/envs/ping2mqtt/lib/python3.8/socket.py", line 231, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/david/.miniconda3/envs/ping2mqtt/lib/python3.8/site-packages/icmplib/ping.py", line 131, in ping
    sock = ICMPv4Socket(
  File "/home/david/.miniconda3/envs/ping2mqtt/lib/python3.8/site-packages/icmplib/sockets.py", line 97, in __init__
    raise SocketPermissionError
icmplib.exceptions.SocketPermissionError: Root privileges are required to create the socket

System details:

Also tried with Python 3.9.4 from within a Docker container, running as root, and when setting the privileged=False setting, the outcome is the same:

>>> from icmplib import ping
>>> ping("8.8.8.8", privileged=False)
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/icmplib/sockets.py", line 88, in __init__
    self._sock = self._create_socket(
  File "/usr/local/lib/python3.9/site-packages/icmplib/sockets.py", line 452, in _create_socket
    return socket.socket(
  File "/usr/local/lib/python3.9/socket.py", line 232, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/icmplib/ping.py", line 131, in ping
    sock = ICMPv4Socket(
  File "/usr/local/lib/python3.9/site-packages/icmplib/sockets.py", line 97, in __init__
    raise SocketPermissionError
icmplib.exceptions.SocketPermissionError: Root privileges are required to create the socket
>>> ping("8.8.8.8")
<Host [8.8.8.8]>
David-Lor commented 3 years ago

nvm, I've missed too the net.ipv4.ping_group_range thing :smile: :facepalm: