Skip to content

Instantly share code, notes, and snippets.

@ecatanzani
Created August 31, 2019 15:20
Show Gist options
  • Save ecatanzani/09a8d3ebbf074f4ff2eba197978da84c to your computer and use it in GitHub Desktop.
Save ecatanzani/09a8d3ebbf074f4ff2eba197978da84c to your computer and use it in GitHub Desktop.
Remote hosts viewer
import subprocess
import os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
hosts = ["host1","host2","host3"]
ids = ["name_host_1","name_host_2","name_host_3"]
for idxHost in range(0,len(hosts)):
with open(os.devnull, "w") as nOut:
tmpHost = str(ids[idxHost]) + "\t\t(" + str(hosts[idxHost]) + ")" "\t............................\t"
res = subprocess.call(['ping', '-c', '3', hosts[idxHost]],stdout=nOut,stderr=nOut)
if res == 0:
print tmpHost + bcolors.OKGREEN + "ONLINE" + bcolors.ENDC
elif res == 2:
print tmpHost + bcolors.FAIL + "OFFLINE" + bcolors.ENDC
else:
print tmpHost + bcolors.WARNING + "ADDRESS FAILED" + bcolors.ENDC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment