While we are trying to run and get the traceroute output using mtrpacket getting below error
import asyncio import mtrpacket # A simple coroutine which will start an mtrpacket session and # ping localhost async def probe(): async with mtrpacket.MtrPacket() as mtr: return await mtr.probe('10.11.12.13') # Use asyncio's event loop to start the coroutine and wait for the probe loop = asyncio.get_event_loop() try: result = loop.run_until_complete(probe()) finally: loop.close() # Print the probe result print(result) Error: mtrpacket.ProcessError: failure to communicate with subprocess "mtr-packet" (is it installed and in the PATH?) mtr-packet: Failure to open IPv4 sockets: Permission denied mtr-packet: Failure to open IPv6 sockets: Permission denied Any suggestions?
12 Answers
Probably socket permissions, try running with sudo access and that might do the trick.
1mtr-packet is designed to run with raw socket access. If you are using Linux, you can use capabilities to grant the binary socket access. On other Unix-like operating systems, including MacOS, it should be suid root.
The following commands will grant it access to raw sockets.
For Linux:
sudo chown root $(which mtr-packet) sudo setcap cap_net_raw+ep $(which mtr-packet) For other operating systems:
sudo chown root $(which mtr-packet) sudo chmod u+s $(which mtr-packet)