how to use pythonping with exectutor

380 Views Asked by At

I'm trying to capture IMCP ping results using pythonping on my Raspberry PI. The documentation says it needs to be ran as root (undesirable), or I can use executor to work around this and run as user Pi using the executor.Communicator function.

I cannot find a working example of how to do this.

My test code is simple

from executor import execute
from pythonping import ping

# get average of 10 pings to host
# gives permission error
#ping("1.1.1.1",size=40,count=10)

# test of executor: capture result to variable
c=execute("hostname",capture=True)
print(c)

Somehow I use executor to process the ping request as a wrapper to get around needing to be root. I'd love for someone to show me a working example of how to do this.

pythonping is exactly what I want because I can tell it to give me the average of 10 pings to a host.

1

There are 1 best solutions below

0
Shawn On

I resolved this by using the icmplib library instead because it fully manages the exchanges and the structure of ICMP packets.

from executor import execute
from icmplib import ping

host=ping("1.1.1.1", count=4, privileged=False)
print(host.avg_rtt)