def changeStatus( delay, destAddr ):
			if delay:
				if self.__status.has_key( destAddr ):
					if self.__status[ destAddr ][ 'Status' ] == False:
						self.activateTerminal( destAddr )
					else:
						return;
				else:
					try:
						host = socket.gethostbyaddr( destAddr )[0]
					except socket.herror, e:
						if e.errno != 11004:
							raise Exception( 'get host name error!' )
						host = destAddr
					mac = getMac( destAddr )
					terminalID = self.setTerminal( destAddr, mac, host )
					self.__status[ destAddr ] = { 'TerminalID':terminalID, 'Name':host, 'IPv4':destAddr, 'Mac':mac }
					queryPackInfo = Packager.nameFindPackage( 'QueryTerminals' )
					OuterService.broadcast( [ 0, queryPackInfo[ 'Code' ], '' ] )
				Logger.info( 'Terminal %s login!'%destAddr )
				self.__status[ destAddr ][ 'Status' ] = True
				queryPackInfo = Packager.nameFindPackage( 'QueryStatus' )
				OuterService.broadcast( [ 0, queryPackInfo[ 'Code' ], '' ] )
					mac = getMac( destAddr )
					terminalID = self.setTerminal( destAddr, mac, host )
					self.__status[ destAddr ] = { 'TerminalID':terminalID, 'Name':host, 'IPv4':destAddr, 'Mac':mac }
					queryPackInfo = Packager.nameFindPackage( 'QueryTerminals' )
					OuterService.broadcast( [ 0, queryPackInfo[ 'Code' ], '' ] )
				Logger.info( 'Terminal %s login!'%destAddr )
				self.__status[ destAddr ][ 'Status' ] = True
				queryPackInfo = Packager.nameFindPackage( 'QueryStatus' )
				OuterService.broadcast( [ 0, queryPackInfo[ 'Code' ], '' ] )
			else:
				if self.__status.has_key( destAddr ):
					if self.__status[ destAddr ][ 'Status' ] == True:
						Logger.info( 'Terminal %s logout!'%destAddr )
						self.__status[ destAddr ][ 'Status' ] = False
						queryPackInfo = Packager.nameFindPackage( 'QueryStatus' )
						OuterService.broadcast( [ 0, queryPackInfo[ 'Code' ], '' ] )
		
		while self.__switch:
			for existsAddr in self.__status.keys():
				ICMP.send_one_ping(mySocket, existsAddr, my_ID)
				delay = ICMP.receive_one_ping(mySocket, my_ID, 1)
				changeStatus( delay, existsAddr )
			
			for i in range( 1, ipCount ):
				destAddr = socket.inet_ntoa( pack( '>L', netAddrBit + i ) )
				if destAddr == IP or self.__status.has_key( destAddr ):
					continue
				ICMP.send_one_ping(mySocket, destAddr, my_ID)
				delay = ICMP.receive_one_ping(mySocket, my_ID, 1)
				changeStatus( delay, destAddr )
			sleep( 30 )