import os,thread,time

class box(object):    
    def __init__(self, name=None, ip=None, present=None):
        self.name = name
        self.ip = ip
        self.present = present
    def checkStatus(self):
        ping = os.popen("ping %s -n 1 -w 450" %(self.ip))
        pingResult= ping.read()    
        #print pingResult
        present = not "100% loss" in pingResult
        if(present!=self.present):            
            eventName='Ping.%s.%s' %(present,self.name)
            vc.triggerEvent(eventName,None)
        self.present=present
        return self.present



def pingLoop(delay):    
    while 1:        
        for target in boxList:
            target.checkStatus()
        time.sleep(delay) # pause between loops

def getPingList():
    mylist=""
    for target in boxList:
        mylist+=target.name
        if target.present:            
            mylist+=" is here, "
        else:
            mylist+=" is not here, "
    mylist = mylist.strip()
    mylist = mylist.strip(',')
    return mylist

boxList = []
boxList.append(box("I7", "192.168.0.125", False))
boxList.append(box("HTPC", "192.168.0.126", False))
boxList.append(box("iPod", "192.168.0.100", False))

#temp disabled
thread.start_new_thread( pingLoop, (60,) )