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 500" %(self.ip))
        pingResult= ping.read()    
        #print pingResult
        present = not "100%" 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:       
        print "looping"
        for target in boxList:
            target.checkStatus()            
        time.sleep(delay) # pause between loops
    print "loop has died?"
    
def pingUpdateOnce():    
    for target in boxList:
        target.checkStatus()            

def getlist():
    mylist=""
    for target in boxList:
        if target.present:
            mylist+=target.name+","
    mylist = mylist.strip(',')
    return mylist

boxList = []
boxList.append(box("I7", "192.168.0.125", False))
boxList.append(box("MSI", "192.168.0.126", False))
boxList.append(box("iPod", "192.168.0.103", False))
boxList.append(box("Android", "192.168.0.100", False))
boxList.append(box("Nardo", "192.168.0.102", False))

#temp disabled
thread.start_new_thread( pingLoop, (120,) )