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 requires root privileges #28

Closed seriousm4x closed 3 years ago

seriousm4x commented 3 years ago

I'm using debian 10 with python3 3.7.3 and pinging doesn't work without being root. This is what I've tried: Package version is 2.0.1

Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from icmplib import ping
>>> test = ping("8.8.8.8", count=1, interval=1, timeout=1, privileged=False)
Traceback (most recent call last):
  File "/home/max/.local/lib/python3.7/site-packages/icmplib/sockets.py", line 88, in __init__
    socket.SOCK_DGRAM)
  File "/home/max/.local/lib/python3.7/site-packages/icmplib/sockets.py", line 448, in _create_socket
    proto=socket.IPPROTO_ICMP)
  File "/usr/lib/python3.7/socket.py", line 151, 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/max/.local/lib/python3.7/site-packages/icmplib/ping.py", line 133, in ping
    privileged=privileged)
  File "/home/max/.local/lib/python3.7/site-packages/icmplib/sockets.py", line 95, in __init__
    raise SocketPermissionError
icmplib.exceptions.SocketPermissionError: Root privileges are required to create the socket
>>>

Edit: It works on my other ubuntu server with python 3.8.5.

seriousm4x commented 3 years ago

Reading the doc helps... I ran sudo sysctl -w net.ipv4.ping_group_range='0 2147483647' and its working now. Sorry...