import bluetooth
import json


class Scanner:
    def __init__(self, vuln_mac_addr_fpath = "./bluetooth_mac_addr.json"):
        '''
        '''
        with open(vuln_mac_addr_fpath, 'r') as vuln_addr_fp:
            self.vuln_addr = json.load(vuln_addr_fp)
        return

    def scan_devices(self):
        '''
        scan bluetooth devices
        '''
        print('[*] Scanning Bluetooth ...')
        self.devices = bluetooth.discover_devices(lookup_names=True, lookup_class=True)
        print('[*] Found {} devices'.format(len(self.devices)))
        for device in self.devices:
            info = {}
            info['mac']  = device[0] # bluetooth mac address name
            info['name'] = device[1] # bluetooth device name
            info['???']  = device[2] # baudrate?
            info['vuln'] = {}

            vendor = ':'.join(info['mac'].split(':')[:3])
            if vendor in self.vuln_addr:
                info['vuln'] = self.vuln_addr[vendor]
            print(info)

       



if __name__ == "__main__":
    scanner = Scanner()
    scanner.scan_devices()

'''
[*] Scanning Bluetooth ...
[*] Found 1 devices
{'???': 7995916, 'mac': '40:98:AD:00:00:00', 'name': 'g0pher iphone', 'vuln': {u'vulns': u'ee'}}
'''

import bluetooth
import json


class Scanner:
    def __init__(self, vuln_mac_addr_fpath = "./bluetooth_mac_addr.json"):
        '''
        '''
        with open(vuln_mac_addr_fpath, 'r') as vuln_addr_fp:
            self.vuln_addr = json.load(vuln_addr_fp)
        return

    def scan_devices(self):
        '''
        scan bluetooth devices
        '''
        print('[*] Scanning Bluetooth ...')
        self.devices = bluetooth.discover_devices(lookup_names=True, lookup_class=True)
        print('[*] Found {} devices'.format(len(self.devices)))
        for device in self.devices:
            info = {}
            info['mac']  = device[0] # bluetooth mac address name
            info['name'] = device[1] # bluetooth device name
            info['???']  = device[2] # baudrate?
            info['vuln'] = {}

            vendor = ':'.join(info['mac'].split(':')[:3])
            if vendor in self.vuln_addr:
                info['vuln'] = self.vuln_addr[vendor]
            print(info)

       



if __name__ == "__main__":
    scanner = Scanner()
    scanner.scan_devices()

'''
[*] Scanning Bluetooth ...
[*] Found 1 devices
{'???': 7995916, 'mac': '40:98:AD:00:00:00', 'name': 'g0pher iphone', 'vuln': {u'vulns': u'ee'}}
'''

scan bluetooth devices # bluetooth mac address name # bluetooth device name # baudrate? [*] Scanning Bluetooth ... [*] Found 1 devices {'???': 7995916, 'mac': '40:98:AD:00:00:00', 'name': 'g0pher iphone', 'vuln': {u'vulns': u'ee'}}