Created
January 14, 2015 11:15
-
-
Save cburbridge/b185c60efc5efbc83bc5 to your computer and use it in GitHub Desktop.
Script to ping all hosts in the /etc/hosts file and report there status.
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
#!/usr/bin/python | |
# Script to ping all hosts in the /etc/hosts file and report there status. | |
import os | |
from time import gmtime, strftime | |
with open("/etc/hosts","r") as f: | |
hosts = f.readlines() | |
print "-" * 70 | |
print strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) | |
for h in hosts: | |
if len(h.strip()) < 1: | |
continue | |
if h.strip().startswith("#"): | |
continue | |
host = h.split()[1] | |
if host.startswith("ip6"): | |
continue | |
print host, " "*(27-len(host)), | |
if os.system("ping -c 1 -w 1 " + host + " > /dev/null 2>&1") == 0: | |
print "live" | |
else: | |
print "down" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment