This script will attempt to check the authentication details for an AP to see if they are correct. It should be called like so:
$ ruby wpa_auth_test.rb "FBISurveillanceVan4" "stingrays 4 eva"
I, [2000-01-02T02:36:27.925647 #14255] INFO -- : Starting WPA Supplicant
I, [2000-01-02T02:36:28.097044 #14255] INFO -- : Searching WPA log for authentication state
I, [2000-01-02T02:36:37.943307 #14255] INFO -- : Found authentication state in 10.02 seconds
I, [2000-01-02T02:36:37.947201 #14255] INFO -- : Killing WPA on PID 14268
E, [2000-01-02T02:36:37.961020 #14255] ERROR -- : Authentication failed
It will give a return status of 1 for auth failure or 0 for success, as well as logging some information to the console.
It has a built in timeout (default 15sec) in case something holds the script up (on a BeagleboneBlack this typically took ~10s for a failed auth, and ~2s for a successful auth). In most cases the WPA supplicant was killed before DHCP could configure the interface.
In the case where the interface is already connected to an AP and configured via WPA/DHCP, this script will cause that connection to drop, regardless of AP auth success or failure. With the latter the connection is promptly restored after the script is finished, however with the former the connection may be momentarily reconfigured via DHCP to the new APs details, before control is given back to the original WPA process. It is unclear if this disconnection can be avoided.
This has only been tested with wpa_supplicant v2.3, the log output from other versions may be different and so may require adjusting of the parse_log
method.