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