]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/wpa/wpa_supplicant/examples/dbus-listen-preq.py
Update hostapd/wpa_supplicant to 2.8 to fix multiple vulnerabilities.
[FreeBSD/FreeBSD.git] / contrib / wpa / wpa_supplicant / examples / dbus-listen-preq.py
1 #!/usr/bin/python
2
3 from __future__ import print_function
4 import dbus
5 import sys
6 import time
7 import gobject
8 from dbus.mainloop.glib import DBusGMainLoop
9
10 WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
11 WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
12 WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
13 WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
14
15 def usage():
16         print("Usage: %s <ifname>" % sys.argv[0])
17         print("Press Ctrl-C to stop")
18
19 def 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
35 if __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()