I want to ping a target IP address, using a specific interface with Python.
One possibility would be to import os
and use the system's ping command.
import os
hostname = "127.0.0.1"
interface = "eth0"
response = os.system("ping -c 2 -I " + interface + " " + hostname)
if response == 0:
print("up")
else:
print("down")
Is there a more OS independent way to ping a target IP, using a specific interface with python?
edit: The suggested duplicate question does not discuss specific interfaces, nor platform independence. Many of the answers reflect the option I've shown in my question.
On a side note, I'd rather not import non-standard python classes.