dbus-listen-preq.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/python
  2. import dbus
  3. import sys
  4. import time
  5. import gobject
  6. from dbus.mainloop.glib import DBusGMainLoop
  7. WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
  8. WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
  9. WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
  10. WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
  11. def usage():
  12. print "Usage: %s <ifname>" % sys.argv[0]
  13. print "Press Ctrl-C to stop"
  14. def ProbeRequest(args):
  15. if 'addr' in args:
  16. print '%.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['addr']),
  17. if 'dst' in args:
  18. print '-> %.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['dst']),
  19. if 'bssid' in args:
  20. print '(bssid %.2x:%.2x:%.2x:%.2x:%.2x:%.2x)' % tuple(args['dst']),
  21. if 'signal' in args:
  22. print 'signal:%d' % args['signal'],
  23. if 'ies' in args:
  24. print 'have IEs (%d bytes)' % len(args['ies']),
  25. print ''
  26. if __name__ == "__main__":
  27. global bus
  28. global wpas_obj
  29. global if_obj
  30. global p2p_iface
  31. dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
  32. bus = dbus.SystemBus()
  33. wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
  34. # Print list of i/f if no one is specified
  35. if (len(sys.argv) < 2) :
  36. usage()
  37. sys.exit(0)
  38. wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
  39. ifname = sys.argv[1]
  40. path = wpas.GetInterface(ifname)
  41. if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
  42. iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
  43. bus.add_signal_receiver(ProbeRequest,
  44. dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
  45. signal_name="ProbeRequest")
  46. iface.SubscribeProbeReq()
  47. gobject.MainLoop().run()