How do I automatically connect to a VPN when using Wi-Fi in OS X? The FBI issued a warning regarding hotel Wi-Fi access points, and any other public access point.
I'd like to make sure my apple device always uses a VPN when using Wi-Fi. That way even if an attacker were to see my data, they would only see an encrypted jumble of bits. Note that this hack can also be applied to HTTPS connections.
How do I ensure that OSX automatically uses a VPN when using Wi-Fi?
I created a script and launch agent that will automatically connect to a VPN connection when it cannot ping a specific address. It could probably be modified in a way that looks at wifi network whitelist and connects to the VPN if the current wifi is not in that list. As it is right now the vpn will always try to connect if it cannot hit an address that is on the vpn network.

The agent calls a shell script every 30 seconds and tries to ping an IP address that is static on the vpn network. If it cannot ping that IP it enables your vpn connection.

If you did this through an Apple Script App, the app icon will always be in your dock. I prefer to have this running automatically in the background.

Clone the project below and follow the directions in the readme. The end result is an installer package that will place a launch agent plist file in /Library/LaunchAgents/ and a shell script in /Library/Application Support/melonsmasher/. 

Be sure to edit the shell script(auto-vpn) with your VPN connection name and an IP address that is on the VPN network. You can change the run interval in the plist file(com.melonsmasher.autovpn.plist). 

https://github.com/MelonSmasher/OSX-AutoVPN