diff options
Diffstat (limited to 'BluetoothPairedDevices.py')
-rw-r--r-- | BluetoothPairedDevices.py | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/BluetoothPairedDevices.py b/BluetoothPairedDevices.py index 6f9f673..e7b1e49 100644 --- a/BluetoothPairedDevices.py +++ b/BluetoothPairedDevices.py @@ -1,44 +1,44 @@ #!/usr/bin/python -import sys +import sys import re import os def ParrotZikMac(): - p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}') - if sys.platform == "linux2": - out = os.popen("bluez-test-device list").read() - res = p.findall(out) - if len(res)>0: - return res[0] + p = re.compile('90:03:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}') + if sys.platform == "linux2": + out = os.popen("bluez-test-device list").read() + res = p.findall(out) + if len(res)>0: + return res[0] - elif sys.platform == "darwin": - fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb") - plist = binplist.BinaryPlist(file_obj=fd) - parsed_plist = plist.Parse() - try : - for mac in parsed_plist['PairedDevices']: - if p.match(mac.replace("-",":")): - return mac.replace("-",":") - except: - pass + elif sys.platform == "darwin": + fd = open("/Library/Preferences/com.apple.Bluetooth.plist", "rb") + plist = binplist.BinaryPlist(file_obj=fd) + parsed_plist = plist.Parse() + try : + for mac in parsed_plist['PairedDevices']: + if p.match(mac.replace("-",":")): + return mac.replace("-",":") + except: + pass - elif sys.platform == "win32": - aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) - aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices') - for i in range(10): - try: - asubkey_name=_winreg.EnumKey(aKey,i) - mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2)) - res = p.findall(mac) - if len(res)>0: - return res[0] + elif sys.platform == "win32": + aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) + aKey = _winreg.OpenKey(aReg, 'SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices') + for i in range(10): + try: + asubkey_name=_winreg.EnumKey(aKey,i) + mac =':'.join(asubkey_name[i:i+2] for i in range(0,12,2)) + res = p.findall(mac) + if len(res)>0: + return res[0] - except EnvironmentError: - pass + except EnvironmentError: + pass if sys.platform == "darwin": - from binplist import binplist + from binplist import binplist elif sys.platform == "win32": - import _winreg
\ No newline at end of file + import _winreg |