# -------------------------------------------------------------------------------------------------------------------------------------------------------------
# Bluetooth scanning for BlueBorne attack
# @Authors:  Authors: Shir, Hodaya and Alexey
# @Version: 1.0
# @Date 07.2019
# -------------------------------------------------------------------------------------------------------------------------------------------------------------
from classes.deviceslist import devices
from prettytable import PrettyTable
from bluetooth import *
import argparse

# global variables
devicelookup = devices.get_devices(
)  # list of devices according to manufacturer


# function search manufacturer of device
def is_device_vulnerable(addr):
    manufacturers = devicelookup["ANDROIDS"]
    for manufacturer in manufacturers:
        # search manufacturer
        lookups = manufacturers[manufacturer]
        for address in lookups:
            if (address == addr[:8]):  # first 4 bytes of bluetooth address
                return True, str(manufacturer)
    return False, 'Don\'t know'


# function that scans bluetooth devices
def FindDevices(_duration):
    # use table to display devices
import time
import bluetooth
from classes.deviceslist import devices

devicelookup = devices.get_devices()

def search():         
    print "searching for devices"
    devices = bluetooth.discover_devices(duration=20, lookup_names = True)
    return devices

def is_device_vulnerable(addr):
    #print "looking up OUI {0}".format(addr[:8])

    manufacturers = devicelookup["ANDROIDS"]

    for manufacturer in manufacturers:
        #print manufacturer
        lookups = manufacturers[manufacturer]
        for _ in lookups:
            if _ == addr[:8]:
                return True
                #print "FOUND : " + _

    return False

if __name__=="__main__":

    print ("\n")
    print ("\x1b[1;35mhook's Blueborne Android scanner v0.01\x1b[0m")
    print ("\n")