2013-06-24 66 views
0

我想用Python來檢查bash命令hcitool scan的輸出是否已知MAC地址。Python hcitool掃描

例如:我將手機的MAC地址保存爲變量。然後,我檢查由hcitool scan確定的所有MAC地址。類似這樣的:

for each (popen('hcitool scan') as $line) 
    if ($line == $mymac) 
     print 'Phone in the Bluetooth range'; 
    else 
     print 'Your phone isn't in the Bluetooth range'; 
+0

爲什麼不直接使用BlueZ? –

+0

這是我運行查詢時獲得的輸出pi @ raspberrypi〜$ sudo python inquiry.py正在執行查詢... Traceback(最近調用最後一個):文件「inquiry.py」,第12行,在 nearby_devices = bluetooth .discover_devices(lookup_names = True)文件「/usr/lib/python2.7/dist-packages/bluetooth/bluez.py」,第22行,位於discover_devices中raise BluetoothError(「與本地通信時出錯」bluetooth.btcommon.BluetoothError:error本地藍牙適配器 – danielebuso

回答

0

是的,那就是PHP。 $變量的名字給它帶來了:)

爲了做到這一點與Python看看PyBluez。雖然它並不真正支持Python 3,但有人可能啓動了一個端口,但我不知道它在哪裏

+0

感謝非常有幫助的溝通=) – danielebuso

+1

這是輸出inquiry.py PI @樹莓派〜$ sudo的蟒蛇運行inquiry.py 進行調查... 回溯(最近最後一次通話)當我得到: 文件「inquiry.py」,第12行,在 nearby_devices = bluetooth.discover_devices(lookup_names = True) 文件「/usr/lib/python2.7/dist-packages/bluetooth/bluez.py」,第22行,在discover_devices中 raise BluetoothError(「與本地通信錯誤」 bluetooth.btcommon.BluetoothError:與本地藍牙適配器通信錯誤 – danielebuso