For checking a device up and down i used
Code: Select all
result = os.system ("ping -c 5 " +hostname)
Code: Select all
packetloss = os.popen ("ping -c 5 " +hostname+ "| grep -oP '\d+(?=% packet loss)'").read().rstrip()
packetloss = int(packetloss)
Code: Select all
result = os.system ("ping -c 5 " +hostname)
Code: Select all
packetloss = os.popen ("ping -c 5 " +hostname+ "| grep -oP '\d+(?=% packet loss)'").read().rstrip()
packetloss = int(packetloss)
Code: Select all
import subprocess
url = "www.google.com"
ping = subprocess.Popen(["ping", "-n", "1", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print ping.stdout.readlines()