Div0 Blog Editor
Staying Connected to a Broken Wi-Fi AP (Mac OS X)
Updated: May 23, 2020
Whilst this is not strictly a cybersecurity-related snippet, it might still be an interesting curiosity for someone working on that field and having to deal with a hostile or just mad Wi-Fi Access Point (AP) which just keeps on dropping the connection.
In this scenario, there is no other more well-behaving APs around, and one just wants to stay online. Rejoining manually and ignoring the connection failure notifications is one way to go, but as the events occur too frequently, they can become a real bottleneck in the production process.
Hence a good solution is for the Mac OS X to build up a small bash script to keep on joining as soon as the connection drops. Luckily Apple provides a built-in command to connect to a Wi-Fi AP with given SSID and password. Building a loop around that is also trivial.
op=1 while [ $op -eq 1 ]; do echo "joining..." xop=$( networksetup -setairportnetwork en0 SSID PASSWORD ) # you could check the return value here, but we just ignore done
This would just keep on joining until killed. And what is funny, it actually solves the issue mostly, as the time gap between the connection dropped and re-established is quite small. Of course one would need to take into account the local network policies, as the AP might consider frequent rejoins as hostile behaviour, depending on the reason of the connection being dropped (for that matter, check the output in "cop" variable).
But, for the curious minds, this is a good learning point, and at least reminds about the powerful network setup command to be used for this and many other manoeuvres.
Kristo Helasvuo, Guest Author.