There's probably a one-liner in Linux too, but not one which satisfies the three caveats in the post.
The necessary infrastructure exists in wpa_supplicant, but only in a newer version than is distributed with Ubuntu 16.04. OpenBSD is more integrated, so advanced functionality like this tends to be easily accessed through ifconfig.