Skip to content

Instantly share code, notes, and snippets.

@cburbridge
Created January 14, 2015 11:15
Show Gist options
  • Save cburbridge/b185c60efc5efbc83bc5 to your computer and use it in GitHub Desktop.
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.
#!/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