1 #!/usr/bin/env python 2 #encoding:utf-8 3 #by i3ekr 4 5 import re 6 import subprocess 7 def check_alive(ip,count=1,timeout=1): 8 com = subprocess.Popen('ping -c %d -W %d %s'%(count,timeout,ip),stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True) 9 result = com.stdout.read() 10 regex = re.findall('100% packet loss', result) 11 if len(regex) == 0: 12 print("