]>
Commit | Line | Data |
---|---|---|
20da5c89 JM |
1 | #!/usr/bin/python |
2 | # | |
3 | # Test script for wpaspy | |
4 | # Copyright (c) 2013, Jouni Malinen <j@w1.fi> | |
5 | # | |
6 | # This software may be distributed under the terms of the BSD license. | |
7 | # See README for more details. | |
8 | ||
9 | import os | |
10 | import time | |
11 | import wpaspy | |
12 | ||
13 | wpas_ctrl = '/var/run/wpa_supplicant' | |
14 | ||
15 | def wpas_connect(): | |
16 | ifaces = [] | |
17 | if os.path.isdir(wpas_ctrl): | |
18 | try: | |
19 | ifaces = [os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)] | |
20 | except OSError, error: | |
21 | print "Could not find wpa_supplicant: ", error | |
22 | return None | |
23 | ||
24 | if len(ifaces) < 1: | |
25 | print "No wpa_supplicant control interface found" | |
26 | return None | |
27 | ||
28 | for ctrl in ifaces: | |
29 | try: | |
30 | wpas = wpaspy.Ctrl(ctrl) | |
31 | return wpas | |
15cb4772 | 32 | except Exception, e: |
20da5c89 JM |
33 | pass |
34 | return None | |
35 | ||
36 | ||
37 | def main(): | |
38 | print "Testing wpa_supplicant control interface connection" | |
39 | wpas = wpas_connect() | |
40 | if wpas is None: | |
41 | return | |
42 | print "Connected to wpa_supplicant" | |
43 | print wpas.request('PING') | |
44 | ||
45 | mon = wpas_connect() | |
46 | if mon is None: | |
47 | print "Could not open event monitor connection" | |
48 | return | |
49 | ||
50 | mon.attach() | |
51 | print "Scan" | |
52 | print wpas.request('SCAN') | |
53 | ||
54 | count = 0 | |
55 | while count < 10: | |
56 | count += 1 | |
57 | time.sleep(1) | |
58 | while mon.pending(): | |
59 | ev = mon.recv() | |
60 | print ev | |
61 | if 'CTRL-EVENT-SCAN-RESULTS' in ev: | |
62 | print 'Scan completed' | |
63 | print wpas.request('SCAN_RESULTS') | |
64 | count = 10 | |
65 | pass | |
66 | ||
67 | ||
68 | if __name__ == "__main__": | |
69 | main() |