Skip to content

Instantly share code, notes, and snippets.

@davidsaccavino
Created June 25, 2018 21:32
Show Gist options
  • Save davidsaccavino/efa2de6b39c9797345c5068ec483a425 to your computer and use it in GitHub Desktop.
Save davidsaccavino/efa2de6b39c9797345c5068ec483a425 to your computer and use it in GitHub Desktop.
#! python 3
# checks if certain ip's ping from a json
import json, os, subprocess
dir = "/Users/david/Desktop/programming/scripts n shit/ping.json"
with open(dir, "r") as f:
data = json.load(f)
for comp in data:
currentIP = data['{}'.format(comp)]['ip']
try:
print(currentIP)
result = str(subprocess.check_output('ping -c 1 {}'.format(currentIP), shell=True))
except subprocess.CalledProcessError:
data['pi']['up'] = 'False'
with open(dir, "w") as f:
json.dump(data, f)
if '1 packets received' in result:
data['{}'.format(comp)]['up'] = 'True'
with open(dir, "w") as f:
json.dump(data, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment