Created
June 25, 2018 21:32
-
-
Save davidsaccavino/efa2de6b39c9797345c5068ec483a425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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