3 # Test script for wpaspy
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
14 wpas_ctrl = '/var/run/wpa_supplicant'
16 def wpas_connect(host=None, port=9877):
21 wpas = wpaspy.Ctrl(host, port)
24 print "Could not connect to host: ", host
27 if os.path.isdir(wpas_ctrl):
29 ifaces = [os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)]
30 except OSError, error:
31 print "Could not find wpa_supplicant: ", error
35 print "No wpa_supplicant control interface found"
40 wpas = wpaspy.Ctrl(ctrl)
47 def main(host=None, port=9877):
48 print "Testing wpa_supplicant control interface connection"
49 wpas = wpas_connect(host, port)
52 print "Connected to wpa_supplicant"
53 print wpas.request('PING')
55 mon = wpas_connect(host, port)
57 print "Could not open event monitor connection"
62 print wpas.request('SCAN')
71 if 'CTRL-EVENT-SCAN-RESULTS' in ev:
72 print 'Scan completed'
73 print wpas.request('SCAN_RESULTS')
78 if __name__ == "__main__":
80 main(host=sys.argv[1], port=int(sys.argv[2]))