#!/usr/bin/env python from subprocess import Popen, PIPE import os, sys ip_list = [] ###### IP addresses ##### # IP addresses go underneath this line, one on each line in the format: ip_list.append('x.x.x.x') ###### End IP addresses shutdown = True for ip in ip_list: cmd = ['/sbin/ping', '-s 0', '-W 1', '-q', '-n' , '-c 1', ip] p1 = Popen(cmd, stdout=PIPE, stderr=PIPE) p1.wait() statusText = p1.communicate()[0].split('\n')[3].strip() if statusText.find(', 0.0% packet loss') > 0: shutdown = False if shutdown: cmd = ['/sbin/shutdown', '-p', 'now'] p1 = Popen(cmd)