Esempio n. 1
0
    def displayDevices(self):
        client = MongoClient(
            'mongodb://ec2-52-89-213-104.us-west-2.compute.amazonaws.com:27017/'
        )
        client.Alfr3d_DB.authenticate(db_user, db_pass)
        db = client['Alfr3d_DB']
        devicesCollection = db['devices']

        result = ""

        for member in devicesCollection.find({'user': self.name}):
            device = Device()
            device.getDetails(member['MAC'])
            result += device.display()

        return result
Esempio n. 2
0
def checkLANMembers():
	"""
		Description:
			This function checks who is on LAN 
	"""
	logger.info("Checking localnet for online devices")
 
	# set up configuration and temporary files
	# config file for daemon specific configs
	configFile = (os.path.join(os.path.join(os.getcwd(),os.path.dirname(__file__)),'../conf/alfr3ddaemon.conf'))
	# temporary file for storing results of network scan
	netclientsfile = os.path.join(os.path.join(os.getcwd(),os.path.dirname(__file__)),'../log/netclients.tmp')
	# temporary file for secondary network scan
	nethostsfile = os.path.join(os.path.join(os.getcwd(),os.path.dirname(__file__)),'../log/nethosts.tmp')

	# depending on where the daemon is running....
	# find out who is online
	if socket.gethostname() == 'psamathe':
		#os.system("sudo arp-scan --interface=p1p1 --localnet > "+ netclientsfile)	#PSAMATHE
		os.system("sudo arp-scan --localnet > "+ netclientsfile)	#PSAMATHE
	else:
		os.system("sudo arp-scan --localnet > "+ netclientsfile)

	netClients = open(netclientsfile, 'r')
	netClientsMACs = []
	netClientsIPs = []
	netClientsHosts = []

	# Parse MAC and IP addresses (depending on host)
	if socket.gethostname() == 'psamathe':
		for line in netClients:
			ret = line.split('\t')
			ret2 = ret[0].split('.')
			if ret2[0] == ('192') and ret2[1] == ('168'):
				print ret[0]
				# parse MAC addresses from arp-scan run
				netClientsMACs.append(ret[1])		
				# parse IP addresses from arp-scan run
				netClientsIPs.append(ret[0])
	else:
		for line in netClients:
			ret = line.split('\t')
			ret2 = ret[0].split('.')
			if ret2[0] == ('10') and ret2[1] == ('0'):
				# parse MAC addresses from arp-scan run
				netClientsMACs.append(ret[1])		
				# parse IP addresses from arp-scan run
				netClientsIPs.append(ret[0])
			elif ret2[0] == ('192') and ret2[1] == ('168'):
				# parse MAC addresses from arp-scan run
				netClientsMACs.append(ret[1])		
				# parse IP addresses from arp-scan run
				netClientsIPs.append(ret[0])

	# clean up and parse MAC&IP info
	netClients2 = {}
	for i in range(len(netClientsMACs)):
		netClients2[netClientsMACs[i]] = netClientsIPs[i]

	# find who is online and 
	# update DB status and last_online time
	for member in netClientsMACs:
		device = Device()
		exists = device.getDetails(member)

		#if device exists in the DB update it
		if exists:
			logger.info("Updating device with MAC: "+member)			
			device.IP = netClients2[member]
			time_away = device.last_online - time()
			device.update()

			# if user is gone for more than 5 minutes... 
			# if time_away > (5*60):
			# 	speakWelcome(device.user, time_away)

		#otherwise, create and add it. 
		else:
			logger.info("Creating a new DB entry for device with MAC: "+member)
			device.IP = netClients2[member]
			device.MAC = member
			device.newDevice(member)		

	logger.info("Updating users")
	user = User()
	user.refreshAll()
	logger.info("Updating devices")
	device = Device()
	device.refreshAll()

	logger.info("Cleaning up temporary files")
	os.system('rm -rf '+netclientsfile)
	os.system('rm -rf '+nethostsfile)