1#!/usr/bin/python 2 3import gobject 4 5import dbus 6import dbus.mainloop.glib 7 8def device_found(address, properties): 9 print "[ " + address + " ]" 10 11 for key in properties.keys(): 12 value = properties[key] 13 if (key == "Class"): 14 print " %s = 0x%06x" % (key, value) 15 else: 16 print " %s = %s" % (key, value) 17 18def discovery_completed(): 19 mainloop.quit() 20 21if __name__ == '__main__': 22 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 23 24 bus = dbus.SystemBus() 25 manager = dbus.Interface(bus.get_object("org.bluez", "/"), 26 "org.bluez.Manager") 27 28 path = manager.DefaultAdapter() 29 adapter = dbus.Interface(bus.get_object("org.bluez", path), 30 "org.bluez.Adapter") 31 32 bus.add_signal_receiver(device_found, 33 dbus_interface = "org.bluez.Adapter", 34 signal_name = "DeviceFound") 35 36 bus.add_signal_receiver(discovery_completed, 37 dbus_interface = "org.bluez.Adapter", 38 signal_name = "DiscoveryCompleted") 39 40 adapter.DiscoverDevices() 41 42 mainloop = gobject.MainLoop() 43 mainloop.run() 44