Last active
December 24, 2015 08:49
-
-
Save Pretz/6773344 to your computer and use it in GitHub Desktop.
Reads the blutooth link key from the windows registry for a given paired bluetooth device (specified via MAC).
Useful for multi-pairing with OS X and Loonix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winreg | |
import itertools | |
import binascii | |
import array | |
def hexlify(_bytes, reverse=True): | |
a = array.array('b', _bytes) | |
if swap: | |
a.reverse() | |
return binascii.hexlify(a.tobytes()).decode('utf-8') | |
MAC = '442a60ef7939' | |
reg_keys = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, | |
'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys') | |
mac_addr = None | |
for i in itertools.count(): | |
try: | |
device_addr = winreg.EnumKey(reg_keys, i) | |
sub_key = winreg.OpenKey(reg_keys, device_addr) | |
for i in itertools.count(): | |
try: | |
mac_addr, key, kind = winreg.EnumValue(sub_key, i) | |
if mac_addr == MAC: | |
print('Key Found: %s, on device: %s' % | |
(hexlify(key), device_addr)) | |
except OSError: | |
break | |
except OSError: | |
break | |
if not mac_addr: | |
print('No bluetooth device with given mac address found. Is it paired?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment